Skip to content

Instantly share code, notes, and snippets.

@randomvariable
Created January 20, 2015 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomvariable/913b18cc3716e83eb6fb to your computer and use it in GitHub Desktop.
Save randomvariable/913b18cc3716e83eb6fb to your computer and use it in GitHub Desktop.
Get some stats on RDS
#!/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