Sha256: b98450b2ab73ca334ba885d9d4c86a7d0b473cb4ae258dd93a4797e7f023ea2e
Contents?: true
Size: 1.92 KB
Versions: 2
Compression:
Stored size: 1.92 KB
Contents
#!/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 def initialize abort "FATAL: specify a DB instance name, see --help for usage" unless opts[:dbinstance_identifier] @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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
riemann-tools-0.2.7 | bin/riemann-aws-rds-status |
riemann-tools-0.2.6 | bin/riemann-aws-rds-status |