Skip to content

Instantly share code, notes, and snippets.

@okochang
Created January 29, 2013 07:09
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 okochang/4662397 to your computer and use it in GitHub Desktop.
Save okochang/4662397 to your computer and use it in GitHub Desktop.
Storage Gatewayの監視用スクリプト(CachePercentDirty)
#!/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 => 'CachePercentDirty',
: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