Skip to content

Instantly share code, notes, and snippets.

@mechamogera
Created November 20, 2012 00:15
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 mechamogera/4115079 to your computer and use it in GitHub Desktop.
Save mechamogera/4115079 to your computer and use it in GitHub Desktop.
CloudWatchから料金情報を取得するRubyスクリプト
require 'aws-sdk'
cw = AWS::CloudWatch.new(:proxy_uri => ENV['HTTP_PROXY'] || ENV['http_proxy'])
cw.metrics.filter('metric_name', 'EstimatedCharges').each do |m|
service_name = m.dimensions.find { |x| x[:name] == 'ServiceName' }
service_name = service_name ? service_name[:value] : "Total"
stats = m.statistics(
:start_time => Time.now - 24 * 3600,
:end_time => Time.now,
:statistics => ['Maximum']
)
printf("%-15s $%s\n", service_name, stats.datapoints.last[:maximum])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment