Created
January 20, 2015 17:33
-
-
Save randomvariable/913b18cc3716e83eb6fb to your computer and use it in GitHub Desktop.
Get some stats on RDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'aws-sdk' | |
@cw = AWS::CloudWatch::Client.new | |
@rds = AWS::RDS::Client.new | |
instances = @rds.describe_db_instances[:db_instances] | |
instances.map do |i| | |
id = i[:db_instance_identifier] | |
allocated_storage = i[:allocated_storage] | |
free_storage_space = (@cw.get_metric_statistics( { namespace: "AWS/RDS", | |
dimensions: [{ name: 'DBInstanceIdentifier', value: id }], | |
period: 60, | |
statistics: ["Maximum"], | |
metric_name: "FreeStorageSpace", | |
start_time: (Time.now - 60).iso8601, | |
end_time: Time.now.iso8601 } )[:datapoints].first[:maximum]) / (1024**3) | |
db_type = i[:engine] | |
cpu = @cw.get_metric_statistics( { namespace: "AWS/RDS", | |
dimensions: [{ name: 'DBInstanceIdentifier', value: id }], | |
period: 60, | |
statistics: ["Average"], | |
metric_name: "CPUUtilization", | |
start_time: (Time.now - 60*60*24).iso8601, | |
end_time: Time.now.iso8601 } )[:datapoints].first[:average] | |
queue = @cw.get_metric_statistics( { namespace: "AWS/RDS", | |
dimensions: [{ name: 'DBInstanceIdentifier', value: id }], | |
period: 60, | |
statistics: ["Maximum"], | |
metric_name: "DiskQueueDepth", | |
start_time: (Time.now - 60*60*24).iso8601, | |
end_time: Time.now.iso8601 } )[:datapoints].first[:maximum] | |
disk_utilization = (allocated_storage-(free_storage_space))/allocated_storage | |
puts "#{id},#{db_type},#{allocated_storage},#{free_storage_space},#{disk_utilization},#{cpu/100},#{queue}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment