Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding monitoring of an RDS instance #109

Merged
merged 7 commits into from
Feb 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions bin/riemann-aws-rds-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
require 'date'
require 'time'
require 'json'

require File.expand_path('../../lib/riemann/tools', __FILE__)

$0 = __FILE__ # Let's not expose our AWS keys in the process list

class Riemann::Tools::AWS
include Riemann::Tools

opt :access_key, "AWS access key", :type => String
opt :secret_key, "Secret access key", :type => String
opt :region, "AWS region", :type => String, :default => 'eu-west-1'
opt :dbinstance_identifier, "DBInstanceIdentifier", :type => String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a default here? Won't you get a .metric_name at https://github.com/aphyr/riemann-tools/pull/109/files#diff-91de02aa50aadb39fa72dbbc2344eae3R35 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or possible a fail if not specified? What's the behavior if you don't specify?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should fail. You need ot know what RDS instance to run against. Didn't know how to do it :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add something like this to initialize:

abort "FATAL: specify a DB instance name, see --help for usage" unless opts[:dbinstance_identifier]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, PR coming!


def initialize
@cloudwatch = Fog::AWS::CloudWatch.new(:aws_access_key_id => opts[:access_key],
:aws_secret_access_key => opts[:secret_key],
:region => opts[:region])
end

def tick
time = Time.new
['DatabaseConnections', 'FreeableMemory', 'FreeStorageSpace', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput', 'ReadThroughput', 'CPUUtilization'].each do |metric|
result = @cloudwatch.get_metric_statistics({"Namespace" => 'AWS/RDS', "MetricName" => "#{metric}", "Statistics" => 'Average', "Dimensions" => [{"Name" => "DBInstanceIdentifier", "Value" => "#{opts[:dbinstance_identifier]}"}], "StartTime" => (time-120).to_time.iso8601, "EndTime" => time.to_time.iso8601, "Period" => 60})
metricsResult = result.data[:body]['GetMetricStatisticsResult']
puts JSON.dump(metricsResult)
if (metricsResult['Datapoints'].length>0)
datapoint = metricsResult['Datapoints'][0]
ev = {:metric => datapoint['Average'],
:service => "#{opts[:dbinstance_identifier]}.#{metric} (#{datapoint['Unit']})",
:description => JSON.dump(metricsResult),
:state => "ok",
:ttl => 300}


report ev
end

end
end
end

Riemann::Tools::AWS.run