forked from vmetrix/vacuumetrix
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Lutz
committed
Jul 15, 2012
1 parent
c08ea1f
commit f13a48c
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env ruby | ||
## grab metrics from AWS cloudwatch | ||
### David Lutz | ||
### 2012-07-15 | ||
### gem install fog --no-ri --no-rdoc | ||
|
||
require 'rubygems' | ||
require 'fog' | ||
require 'json' | ||
require '/opt/vacuumetrix/conf/config.rb' | ||
require '/opt/vacuumetrix/lib/Sendit.rb' | ||
|
||
if ARGV.length != 1 | ||
puts "I need one argument. The ELB name" | ||
exit 1 | ||
end | ||
|
||
dimensionId = ARGV[0] | ||
|
||
#AWS cloudwatch stats seem to be a minute or so behind | ||
|
||
startTime = Time.now.utc-180 | ||
endTime = Time.now.utc-120 | ||
|
||
|
||
metricNames = { "RequestCount" => "Sum", | ||
"HealthyHostCount" => "Minimum", | ||
"UnHealthyHostCount" => "Maximum", | ||
"HTTPCode_ELB_5XX" => "Sum", | ||
"HTTPCode_ELB_4XX" => "Sum", | ||
"HTTPCode_Backend_2XX" => "Sum", | ||
"HTTPCode_Backend_3XX" => "Sum", | ||
"HTTPCode_Backend_4XX" => "Sum", | ||
"HTTPCode_Backend_5XX" => "Sum" | ||
} | ||
|
||
unit = 'Count' | ||
|
||
cloudwatch = Fog::AWS::CloudWatch.new(:aws_secret_access_key => $awssecretkey, :aws_access_key_id => $awsaccesskey) | ||
|
||
metricNames.each do |metricName, statistic| | ||
response = cloudwatch.get_metric_statistics({ | ||
'Statistics' => statistic, | ||
'StartTime' => startTime.iso8601, | ||
'EndTime' => endTime.iso8601, | ||
'Period' => 60, | ||
'Unit' => unit, | ||
'MetricName' => metricName, | ||
'Namespace' => 'AWS/ELB', | ||
'Dimensions' => [{ | ||
'Name' => 'LoadBalancerName', | ||
'Value' => dimensionId | ||
}] | ||
}).body['GetMetricStatisticsResult']['Datapoints'] | ||
|
||
metricpath = "AWScloudwatch.ELB." + dimensionId + "." + metricName | ||
begin | ||
metricvalue = response.first[statistic] | ||
rescue | ||
metricvalue = 0 | ||
end | ||
metrictimestamp = endTime.to_i.to_s | ||
|
||
Sendit metricpath, metricvalue, metrictimestamp | ||
end |