riemann-aws-rds 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84fdfe3348cabe4e4b01309f16e9d4365495ac0f
4
+ data.tar.gz: a926a49e9b6fabb058ce00953f6e1f4d8febe729
5
+ SHA512:
6
+ metadata.gz: a35ee685680aae0f595b677c976746f31e28bdc2994da22414745b90d48a40b8e596313529d1a9e7c42dc5a3ae7e7aaa846ed0a613e32fa3f0781a70bb236c5d
7
+ data.tar.gz: 7dc797d629ed8d6c92f56c691813253b30996c0070234bc97f3da0e29daa12919cea97831ab41e700d693092f0137eae1a8c0618e7947a67042ae8bfad716504
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Riemann Aws Rds
2
+ =============
3
+
4
+ Riemann Aws Rds agent.
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Riemann agent to collect Rpush metrics
4
+
5
+ require 'fog'
6
+ require 'riemann/tools'
7
+ require 'json'
8
+
9
+ class Riemann::Tools::AwsRds
10
+ include Riemann::Tools
11
+
12
+ opt :access_key, "AWS access key", :type => String
13
+ opt :secret_key, "Secret access key", :type => String
14
+ opt :region, "AWS region", :type => String, :default => 'us-east-1'
15
+ opt :database, "DB Instance identifiers", :type => String, :multi => true
16
+ opt :metric, "Metric names with comma-separated warning/critical thresholds (eg., 'CPUUtilization,50,90'). Multiple tuples can be set.", :type => String, :multi => true
17
+
18
+ def initialize
19
+ abort "FATAL: specify a DB instances list, see --help for usage" unless opts[:database]
20
+ @databases = opts.fetch(:database)
21
+ @metrics = opts.fetch(:metric).inject({}) do |h, arg|
22
+ metric, warning, critical = arg.split(",")
23
+ h[metric] = { warning: warning.to_i, critical: critical.to_i }; h
24
+ end
25
+ @cloudwatch = Fog::AWS::CloudWatch.new(:aws_access_key_id => opts[:access_key],
26
+ :aws_secret_access_key => opts[:secret_key],
27
+ :region => opts[:region])
28
+ end
29
+
30
+ def tick
31
+ # ['DatabaseConnections', 'FreeableMemory', 'FreeStorageSpace', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput', 'ReadThroughput', 'CPUUtilization'].each do |metric|
32
+ time = Time.new
33
+ @databases.each do |database|
34
+ @metrics.each_pair do |metric, thresholds|
35
+ result = @cloudwatch.get_metric_statistics({"Namespace" => 'AWS/RDS', "MetricName" => "#{metric}", "Statistics" => 'Average', "Dimensions" => [{"Name" => "DBInstanceIdentifier", "Value" => "#{database}"}], "StartTime" => (time-120).to_time.iso8601, "EndTime" => time.to_time.iso8601, "Period" => 60})
36
+ metric_result = result.data[:body]['GetMetricStatisticsResult']
37
+ puts JSON.dump(metric_result)
38
+ if (metric_result['Datapoints'].length > 0)
39
+ datapoint = metric_result['Datapoints'][0]
40
+ value = datapoint['Average']
41
+
42
+ state = if value >= @metrics[metric][:critical]
43
+ 'critical'
44
+ elsif value >= @metrics[metric][:warning]
45
+ 'warning'
46
+ else
47
+ 'ok'
48
+ end
49
+
50
+ msg = {
51
+ metric: datapoint['Average'],
52
+ service: "#{database}.#{metric} (#{datapoint['Unit']})",
53
+ state: state,
54
+ ttl: 120
55
+ }
56
+
57
+ report msg
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ Riemann::Tools::AwsRds.run
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "riemann-aws-rds"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Fernando Alonso"]
9
+ spec.email = ["krakatoa1987@gmail.com"]
10
+ spec.summary = %q{Riemann agent to collect Aws Rds metrics}
11
+ spec.description = %q{Riemann agent to collect Aws Rds metrics}
12
+ spec.homepage = "https://github.com/krakatoa/riemann-aws-rds"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "riemann-tools", "~> 0.2.6"
21
+ spec.add_runtime_dependency 'fog', '~> 1.27'
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-aws-rds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Alonso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riemann-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.27'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.27'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ description: Riemann agent to collect Aws Rds metrics
56
+ email:
57
+ - krakatoa1987@gmail.com
58
+ executables:
59
+ - riemann-aws-rds
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - LICENSE
65
+ - README.md
66
+ - bin/riemann-aws-rds
67
+ - riemann-aws-rds.gemspec
68
+ homepage: https://github.com/krakatoa/riemann-aws-rds
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.8
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Riemann agent to collect Aws Rds metrics
92
+ test_files: []