Created
January 29, 2013 07:11
-
-
Save okochang/4662404 to your computer and use it in GitHub Desktop.
Storage Gatewayの監視用スクリプト(CachePercentUsed)
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
#!/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'aws-sdk' | |
require 'time' | |
ACCESS_KEY = "#{ARGV[0]}" | |
SECRET_KEY = "#{ARGV[1]}" | |
gateway_id = "#{ARGV[2]}" | |
gateway_name = "#{ARGV[3]}" | |
REGION = "#{ARGV[4]}" | |
start_time = Time.now - 10800 | |
end_time = Time.now | |
## AWSへの認証を行います | |
cw = AWS::CloudWatch.new( | |
:access_key_id => ACCESS_KEY, | |
:secret_access_key => SECRET_KEY, | |
:cloud_watch_endpoint => REGION | |
).client | |
## メトリクスのオプションを指定して値を取得します | |
statistics = cw.get_metric_statistics({ | |
:namespace => 'AWS/StorageGateway', | |
:metric_name => 'CachePercentUsed', | |
:statistics => ['Average'], | |
:dimensions => [ | |
{ :name => "GatewayId", :value => gateway_id }, | |
{ :name => "GatewayName", :value => gateway_name } | |
], | |
:period => 300, | |
:start_time => start_time.iso8601, | |
:end_time => end_time.iso8601, | |
}) | |
## 値を出力します | |
p statistics[:datapoints][0][:average] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment