Sha256: 15d4ee79a603b12ee62303a0a1b80e24bf21edccdefe88b302e5c0baca4fa3d7
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
#!/usr/bin/env ruby Process.setproctitle($0) require 'riemann/tools' $0 = __FILE__ # Let's not expose our AWS keys in the process list class Riemann::Tools::AWS include Riemann::Tools require 'fog' require 'date' require 'time' require 'json' 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] if opts[:access_key] and opts[:secret_key] creds = { :aws_access_key_id => opts[:access_key], :aws_secret_access_key => opts[:secret_key] } else creds = { :use_iam_profile => true } end creds['region'] = opts[:region] @cloudwatch = Fog::AWS::CloudWatch.new(creds) 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'] 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
riemann-tools-1.0.0 | tools/riemann-aws/bin/riemann-aws-rds-status |