Skip to content

Instantly share code, notes, and snippets.

@jkkitakita
Created February 19, 2017 01:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkkitakita/ec1b3ee9be3d887898de7766860b350a to your computer and use it in GitHub Desktop.
Save jkkitakita/ec1b3ee9be3d887898de7766860b350a to your computer and use it in GitHub Desktop.
[Grafana] Grafanaで、AWSのリザーブドインスタンス(RI)を監視してみた。 ref: http://qiita.com/jkkitakita/items/6155ff7899eb9d701611
#!/bin/bash
### check instance status is running
/usr/bin/aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" |
jq -r '[ .Reservations[] | .Instances[] | { InstanceType } ]| group_by(.InstanceType) | .
[]|.[0] + { "Count": length}| .InstanceType, .Count'|sed 'N;s/\n/ value=/'|sed 's/^/instan
ces,instance_type=/'
/etc/init.d/telegraf restart
#!/bin/bash
# count of rds db instaces group by instance_type
/usr/bin/aws rds describe-db-instances --output json | jq -r '[.DBInstances[] | { DBInstan
ceClass }] | group_by(.DBInstanceClass) | .[] | .[0] + { "Count": length } | [.DBInstanceC
lass, (.Count|tostring)] | join(",")' | sed 's/^/rds_db_instances,db_instance_type=/g'| aw
k -F, '{print $1 "," $2 " values=" $3}'
# count of reserved rds db instances group by instance_type
/usr/bin/aws rds describe-reserved-db-instances --output json | jq -r '.ReservedDBInstance
s[] | select(.State == "active") | [.DBInstanceClass, (.DBInstanceCount|tostring), .StartT
ime] | join(",")' | sed -E 's/^(.*T.*)\..*$/\1/g' | awk -F, '{print "rds_reserved_instance
s,db_instance_type=" $1 ",start_time=" $3 " RI_count=" $2}'
#!/bin/bash
# count of redshift nodes
/usr/bin/aws redshift describe-clusters --output json | jq -r '[.Clusters[] | select(.Node
Type == "dc1.large") | .NumberOfNodes] | add' | sed 's/^/redshift_cluster_nodes,node_type=
dc1.large values=/g'
# count of reserved redshift nodes
/usr/bin/aws redshift describe-reserved-nodes --output json | jq -r '.ReservedNodes[] | se
lect(.State == "active") | [.NodeType, (.NodeCount|tostring), .StartTime] | join(",")' | s
ed -E 's/^(.*T.*)\..*$/\1/g' | awk -F, '{print "redshift_reserved_nodes,node_type=" $1 ",s
tart_time=" $3 " RI_count=" $2}'
#!/bin/bash
/usr/bin/aws ec2 describe-reserved-instances --filters "Name=state,Values=active" | jq -r
'.ReservedInstances[] | [.InstanceType, .AvailabilityZone, (.InstanceCount|tostring), .End
] | join(",")' | sed 's/T.*//g' | awk -F, '{print "reserved_instances,instance_type=" $1 "
,AvailabilityZone=" $2 ",end_date=" $4 " RI_count=" $3}' | sed 's/=,/=-,/g'
# EC2
[[inputs.exec]]
command = "/etc/telegraf/telegraf.d/exec/count-instances"
data_format = "influx"
interval = "3600s"
[[inputs.exec]]
command = "/etc/telegraf/telegraf.d/exec/reserved_instance.sh"
data_format = "influx"
interval = "3600s"
# RDS
[[inputs.exec]]
command = "/etc/telegraf/telegraf.d/exec/rds_reserved_nodes.sh"
data_format = "influx"
interval = "3600s"
# Redshift
[[inputs.exec]]
command = "/etc/telegraf/telegraf.d/exec/redshift_reserved_nodes.sh"
data_format = "influx"
interval = "3600s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment