Skip to content

Instantly share code, notes, and snippets.

View aerostitch's full-sized avatar

aerostitch aerostitch

View GitHub Profile
@aerostitch
aerostitch / aws_kinesis_check_enhanced_monitoring.sh
Last active January 19, 2018 00:12
Checks if the "per-shard" enhanced monitoring is active for all your kinesis streams.
for s in $(aws kinesis list-streams --query 'StreamNames[*]' --output text); do
if [[ $(aws kinesis describe-stream --stream-name $s --query 'StreamDescription.EnhancedMonitoring.ShardLevelMetrics') != "null" ]]; then
echo "Activated for ${s}";
fi ;
done
package main
// This script reports the number of metrics in cloudwatch for each namespace /
// metric / metric dimension that can be pulled over the last 2 hours. It helps
// tracking the density of the metrics and this way find who stores at least 1
// metric per second. This is needed when you try to track down the spend in the
// monthly report for the PutMetrics operation.
// Outputs the result in a CSV format in the given file path.
//
// usage example:
package main
// Note: I initially wrote this script to delete old Cloudwatch metrics
// but I found out too late that it's not possible to do delete metrics from CloudWatch
// so just keeping this script as a usage example of the metrics statistics manipulations
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
package main
// Parses classic ELB access logs and puts them inside a MySQL/MariaDB table
// Easy way to get a DB:
// docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=accesslogs -p 3306:3306 -d mariadb:latest
//
// The bulk load your files:
// for f in ~/Downloads/*.txt ; do go run aws_elb_log_analyzer.go -db-create-table -db-host "tcp(172.17.0.2)" -db-name accesslogs -db-user root -db-pwd my-secret-pw -db-table bla -file-path $f; done
// Or:
// TBL=bla ; find /tmp/${TBL} -type f -name '*.log' -o -name '*.txt' | while read f; do echo "Processing $f"; go run aws_elb_log_analyzer.go -db-create-table -db-host "tcp(172.17.0.2)" -db-name accesslogs -db-user root -db-pwd my-secret-pw -db-table ${TBL} -file-path $f; done
@aerostitch
aerostitch / aws_elb_list_number_of_instances.sh
Last active June 10, 2022 22:14
Lists all the ELB names and the number of instances attached to them
aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].{name:LoadBalancerName,instances:Instances[*].InstanceId}' | jq '[.[] | {name: .name, inst: .instances | length}]'
# List only the empty ones:
aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].{name:LoadBalancerName,instances:Instances[*].InstanceId}' | jq '[.[] | if (.instances | length) <= 0 then {name: .name, number_of_instances: .instances | length} else empty end]'
@aerostitch
aerostitch / aws_cleanup_cloudwatch.go
Last active April 28, 2021 17:47
Delete empty log streams or logs streams that have only elements older than 30 days in it
package main
// This script cleans up old LogGroups (empty and olde than 90 days and old
// LogStreams (last event timestamp is over 30 days old or if the logstream
// is empty and has been created over 30 days ago) from AWS Cloudwatch
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"log"
export AWS_PROFILE=dev; for lg in $(aws logs describe-log-groups --query 'logGroups[].logGroupName' --output text); do aws logs describe-log-streams --log-group-name "${lg}" --query 'logStreams[].{arn:arn,rs:lastEventTimestamp}' --output text ; done > /tmp/${AWS_PROFILE}.out ; cp /tmp/${AWS_PROFILE}.out /tmp/{AWS_PROFILE}.sh ; sed 's/^arn:aws:logs:.*:.*:log-group:\(.*\):log-stream:\(.*\)\t\+\(.*\) *$/if [[ $(( \3 \/ 1000 )) -lt $(date +%s -d "-30 days") ]] ; then aws logs delete-log-stream --log-group-name '"'"'\1'"'"' --log-stream-name '"'"'\2'"'"'; fi/g' -i /tmp/{AWS_PROFILE}.sh; bash /tmp/{AWS_PROFILE}.sh
# records from the webcam and my bass pedal
ffmpeg -f v4l2 -thread_queue_size 512 -i /dev/video0 -thread_queue_size 512 \
-f alsa -i hw:1,0 -c:v copy -c:a copy \
${HOME}/Videos/$(date +%Y%m%d%H%M)_record.mkv
# ffmpeg -f v4l2 -thread_queue_size 512 -i /dev/video0 \
# -thread_queue_size 512 \
# -f alsa -i hw:1,0 \
# -vcodec libx264 -x264opts keyint=60:no-scenecut -preset fast \
# -q:v 4 -s 640x480 -r 30 /
# -acodec libmp3lame -q:a 7 -channels 2 \
@aerostitch
aerostitch / awsEC2ListInstancesTags.go
Created September 18, 2017 22:17
This script lists the ec2 instances, their status and tags
package main
// This script lists the ec2 instances, their status and tags
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"log"
@aerostitch
aerostitch / awsSGRulesReporter.go
Created September 16, 2017 01:08
This script export all the security groups (not the stale ones) and corresponding rules to the stdout in a csv format
package main
// This script export all the security groups (not the stale ones) and corresponding rules to the stdout in a csv format
// Quickn dirty version
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"log"