riemann-tools 0.2.14 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.docker/Dockerfile +7 -0
- data/.docker/publish.sh +35 -0
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +31 -0
- data/CHANGELOG.md +393 -0
- data/Gemfile +6 -0
- data/ISSUE_TEMPLATE.md +15 -0
- data/README.markdown +14 -1
- data/Rakefile +21 -0
- data/bin/riemann-apache-status +1 -0
- data/bin/riemann-bench +1 -0
- data/bin/riemann-cloudant +1 -0
- data/bin/riemann-consul +1 -0
- data/bin/riemann-dir-files-count +1 -0
- data/bin/riemann-dir-space +1 -0
- data/bin/riemann-diskstats +1 -0
- data/bin/riemann-fd +1 -0
- data/bin/riemann-freeswitch +1 -0
- data/bin/riemann-haproxy +1 -0
- data/bin/riemann-health +19 -11
- data/bin/riemann-kvminstance +1 -0
- data/bin/riemann-memcached +1 -0
- data/bin/riemann-net +1 -0
- data/bin/riemann-nginx-status +1 -0
- data/bin/riemann-ntp +1 -0
- data/bin/riemann-portcheck +1 -0
- data/bin/riemann-proc +1 -0
- data/bin/riemann-varnish +1 -0
- data/bin/riemann-zookeeper +1 -0
- data/lib/riemann/tools/utils.rb +17 -0
- data/lib/riemann/tools/version.rb +7 -0
- data/lib/riemann/tools.rb +12 -2
- data/riemann-tools.gemspec +39 -0
- data/tools/riemann-aws/LICENSE +21 -0
- data/tools/riemann-aws/README.md +54 -0
- data/tools/riemann-aws/Rakefile.rb +35 -0
- data/tools/riemann-aws/bin/riemann-aws-billing +87 -0
- data/tools/riemann-aws/bin/riemann-aws-rds-status +54 -0
- data/tools/riemann-aws/bin/riemann-aws-sqs-status +44 -0
- data/tools/riemann-aws/bin/riemann-aws-status +71 -0
- data/tools/riemann-aws/bin/riemann-elb-metrics +167 -0
- data/tools/riemann-aws/bin/riemann-s3-list +82 -0
- data/tools/riemann-aws/bin/riemann-s3-status +99 -0
- data/tools/riemann-chronos/LICENSE +21 -0
- data/tools/riemann-chronos/README.md +10 -0
- data/tools/riemann-chronos/Rakefile.rb +35 -0
- data/tools/riemann-chronos/bin/riemann-chronos +144 -0
- data/tools/riemann-docker/LICENSE +21 -0
- data/tools/riemann-docker/README.md +10 -0
- data/tools/riemann-docker/Rakefile.rb +34 -0
- data/tools/riemann-docker/bin/riemann-docker +217 -0
- data/tools/riemann-elasticsearch/LICENSE +21 -0
- data/tools/riemann-elasticsearch/README.md +10 -0
- data/tools/riemann-elasticsearch/Rakefile.rb +35 -0
- data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +166 -0
- data/tools/riemann-marathon/LICENSE +21 -0
- data/tools/riemann-marathon/README.md +10 -0
- data/tools/riemann-marathon/Rakefile.rb +35 -0
- data/tools/riemann-marathon/bin/riemann-marathon +147 -0
- data/tools/riemann-mesos/LICENSE +21 -0
- data/tools/riemann-mesos/README.md +10 -0
- data/tools/riemann-mesos/Rakefile.rb +35 -0
- data/tools/riemann-mesos/bin/riemann-mesos +131 -0
- data/tools/riemann-munin/LICENSE +21 -0
- data/tools/riemann-munin/README.md +10 -0
- data/tools/riemann-munin/Rakefile.rb +34 -0
- data/tools/riemann-munin/bin/riemann-munin +37 -0
- data/tools/riemann-rabbitmq/LICENSE +21 -0
- data/tools/riemann-rabbitmq/README.md +10 -0
- data/tools/riemann-rabbitmq/Rakefile.rb +35 -0
- data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +269 -0
- data/tools/riemann-riak/LICENSE +21 -0
- data/tools/riemann-riak/README.md +10 -0
- data/tools/riemann-riak/Rakefile.rb +34 -0
- data/tools/riemann-riak/bin/riemann-riak +331 -0
- data/tools/riemann-riak/bin/riemann-riak-keys +13 -0
- data/tools/riemann-riak/bin/riemann-riak-ring +9 -0
- data/tools/riemann-riak/riak_status/key_count.erl +13 -0
- data/tools/riemann-riak/riak_status/riak_status.rb +152 -0
- data/tools/riemann-riak/riak_status/ringready.erl +9 -0
- metadata +134 -34
data/bin/riemann-consul
CHANGED
data/bin/riemann-dir-files-count
CHANGED
data/bin/riemann-dir-space
CHANGED
data/bin/riemann-diskstats
CHANGED
data/bin/riemann-fd
CHANGED
data/bin/riemann-freeswitch
CHANGED
data/bin/riemann-haproxy
CHANGED
data/bin/riemann-health
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
2
3
|
|
3
4
|
# Reports current CPU, disk, load average, and memory use to riemann.
|
4
5
|
|
5
6
|
require File.expand_path('../../lib/riemann/tools', __FILE__)
|
7
|
+
require File.expand_path('../../lib/riemann/tools/utils', __FILE__)
|
6
8
|
|
7
9
|
class Riemann::Tools::Health
|
8
10
|
include Riemann::Tools
|
11
|
+
include Riemann::Tools::Utils
|
9
12
|
|
10
13
|
opt :cpu_warning, "CPU warning threshold (fraction of total jiffies)", :default => 0.9
|
11
14
|
opt :cpu_critical, "CPU critical threshold (fraction of total jiffies)", :default => 0.95
|
@@ -57,6 +60,7 @@ class Riemann::Tools::Health
|
|
57
60
|
@disk = method :disk
|
58
61
|
@load = method :linux_load
|
59
62
|
@memory = method :linux_memory
|
63
|
+
@supports_exclude_type = `df --help 2>&1 | grep -e "--exclude-type"` != ""
|
60
64
|
end
|
61
65
|
|
62
66
|
opts[:checks].each do |check|
|
@@ -109,7 +113,7 @@ class Riemann::Tools::Health
|
|
109
113
|
total = used + i2-i1
|
110
114
|
fraction = used.to_f / total
|
111
115
|
|
112
|
-
report_pct :cpu, fraction, "user+nice+system\n\n#{`ps -eo pcpu,pid,comm
|
116
|
+
report_pct :cpu, fraction, "user+nice+system\n\n#{reverse_numeric_sort_with_header(`ps -eo pcpu,pid,comm`)}"
|
113
117
|
end
|
114
118
|
|
115
119
|
@old_cpu = [u2, n2, s2, i2]
|
@@ -138,7 +142,7 @@ class Riemann::Tools::Health
|
|
138
142
|
total = m['MemTotal'].to_i
|
139
143
|
fraction = 1 - (free.to_f / total)
|
140
144
|
|
141
|
-
report_pct :memory, fraction, "used\n\n#{`ps -eo pmem,pid,comm
|
145
|
+
report_pct :memory, fraction, "used\n\n#{reverse_numeric_sort_with_header(`ps -eo pmem,pid,comm`)}"
|
142
146
|
end
|
143
147
|
|
144
148
|
def freebsd_cpu
|
@@ -151,7 +155,7 @@ class Riemann::Tools::Health
|
|
151
155
|
total = used + i2-i1
|
152
156
|
fraction = used.to_f / total
|
153
157
|
|
154
|
-
report_pct :cpu, fraction, "user+nice+sytem+interrupt\n\n#{`ps -axo pcpu,pid,comm
|
158
|
+
report_pct :cpu, fraction, "user+nice+sytem+interrupt\n\n#{reverse_numeric_sort_with_header(`ps -axo pcpu,pid,comm`)}"
|
155
159
|
end
|
156
160
|
|
157
161
|
@old_cpu = [u2, n2, s2, t2, i2]
|
@@ -167,7 +171,7 @@ class Riemann::Tools::Health
|
|
167
171
|
total = used + i2-i1
|
168
172
|
fraction = used.to_f / total
|
169
173
|
|
170
|
-
report_pct :cpu, fraction, "user+nice+sytem+interrupt\n\n#{`ps -axo pcpu,pid,comm
|
174
|
+
report_pct :cpu, fraction, "user+nice+sytem+interrupt\n\n#{reverse_numeric_sort_with_header(`ps -axo pcpu,pid,comm`)}"
|
171
175
|
end
|
172
176
|
|
173
177
|
@old_cpu = [u2, n2, s2, t2, i2]
|
@@ -191,7 +195,7 @@ class Riemann::Tools::Health
|
|
191
195
|
fraction = used.to_f / total
|
192
196
|
end
|
193
197
|
|
194
|
-
report_pct :cpu, fraction, "user+sytem+interrupt\n\n#{`ps -ao pcpu,pid,comm
|
198
|
+
report_pct :cpu, fraction, "user+sytem+interrupt\n\n#{reverse_numeric_sort_with_header(`ps -ao pcpu,pid,comm`)}"
|
195
199
|
end
|
196
200
|
|
197
201
|
@old_cpu = [u2, s2, t2, i2]
|
@@ -213,14 +217,14 @@ class Riemann::Tools::Health
|
|
213
217
|
meminfo = `sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count 2>/dev/null`.chomp.split
|
214
218
|
fraction = (meminfo[1].to_f + meminfo[2].to_f) / meminfo[0].to_f
|
215
219
|
|
216
|
-
report_pct :memory, fraction, "used\n\n#{`ps -axo pmem,pid,comm
|
220
|
+
report_pct :memory, fraction, "used\n\n#{reverse_numeric_sort_with_header(`ps -axo pmem,pid,comm`)}"
|
217
221
|
end
|
218
222
|
|
219
223
|
def openbsd_memory
|
220
224
|
meminfo = `vmstat 2>/dev/null`.chomp.split
|
221
225
|
fraction = meminfo[28].to_f / meminfo[29].to_f #The ratio of active to free memory unlike the others :(
|
222
226
|
|
223
|
-
report_pct :memory, fraction, "used\n\n#{`ps -axo pmem,pid,comm
|
227
|
+
report_pct :memory, fraction, "used\n\n#{reverse_numeric_sort_with_header(`ps -axo pmem,pid,comm`)}"
|
224
228
|
end
|
225
229
|
|
226
230
|
def sunos_memory
|
@@ -228,7 +232,7 @@ class Riemann::Tools::Health
|
|
228
232
|
total_mem = `prtconf | grep Memory`.split[2].to_f * 1024 # reports in GB but vmstat is in MB
|
229
233
|
fraction = ( total_mem - meminfo[32].to_f ) / total_mem
|
230
234
|
|
231
|
-
report_pct :memory, fraction, "used\n\n#{`ps -ao pmem,pid,comm
|
235
|
+
report_pct :memory, fraction, "used\n\n#{reverse_numeric_sort_with_header(`ps -ao pmem,pid,comm`)}"
|
232
236
|
end
|
233
237
|
|
234
238
|
def darwin_top
|
@@ -264,7 +268,7 @@ class Riemann::Tools::Health
|
|
264
268
|
alert 'cpu', :unknown, nil, "unable to get CPU stats from top"
|
265
269
|
return false
|
266
270
|
end
|
267
|
-
report_pct :cpu, @topdata[:cpu], "usage\n\n#{`ps -eo pcpu,pid,comm
|
271
|
+
report_pct :cpu, @topdata[:cpu], "usage\n\n#{reverse_numeric_sort_with_header(`ps -eo pcpu,pid,comm`)}"
|
268
272
|
end
|
269
273
|
|
270
274
|
def darwin_load
|
@@ -289,7 +293,7 @@ class Riemann::Tools::Health
|
|
289
293
|
alert 'memory', :unknown, nil, "unable to get memory data from top"
|
290
294
|
return false
|
291
295
|
end
|
292
|
-
report_pct :memory, @topdata[:memory], "usage\n\n#{`ps -eo pmem,pid,comm
|
296
|
+
report_pct :memory, @topdata[:memory], "usage\n\n#{reverse_numeric_sort_with_header(`ps -eo pmem,pid,comm`)}"
|
293
297
|
end
|
294
298
|
|
295
299
|
def df
|
@@ -299,7 +303,11 @@ class Riemann::Tools::Health
|
|
299
303
|
when 'sunos'
|
300
304
|
`df -P` # Is there a good way to exlude iso9660 here?
|
301
305
|
else
|
302
|
-
|
306
|
+
if @supports_exclude_type
|
307
|
+
`df -P --exclude-type=iso9660 --exclude-type=nfs`
|
308
|
+
else
|
309
|
+
`df -P`
|
310
|
+
end
|
303
311
|
end
|
304
312
|
end
|
305
313
|
|
data/bin/riemann-kvminstance
CHANGED
data/bin/riemann-memcached
CHANGED
data/bin/riemann-net
CHANGED
data/bin/riemann-nginx-status
CHANGED
data/bin/riemann-ntp
CHANGED
data/bin/riemann-portcheck
CHANGED
data/bin/riemann-proc
CHANGED
data/bin/riemann-varnish
CHANGED
data/bin/riemann-zookeeper
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Riemann
|
4
|
+
module Tools
|
5
|
+
module Utils # :nodoc:
|
6
|
+
def reverse_numeric_sort_with_header(data, header: 1, count: 10)
|
7
|
+
lines = data.chomp.split("\n")
|
8
|
+
header = lines.shift(header)
|
9
|
+
|
10
|
+
lines.sort_by!(&:to_f)
|
11
|
+
lines.reverse!
|
12
|
+
|
13
|
+
(header + lines[0, count]).join("\n")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/riemann/tools.rb
CHANGED
@@ -34,6 +34,11 @@ module Riemann
|
|
34
34
|
opt :attribute, "Attribute to add to the event", :type => String, :multi => true
|
35
35
|
opt :timeout, "Timeout (in seconds) when waiting for acknowledgements", :default => 30
|
36
36
|
opt :tcp, "Use TCP transport instead of UDP (improves reliability, slight overhead.", :default => true
|
37
|
+
opt :tls, "Use TLS for securing traffic", :default => false
|
38
|
+
opt :tls_key, "TLS Key to use when using TLS", :type => String
|
39
|
+
opt :tls_cert, "TLS Certificate to use when using TLS", :type => String
|
40
|
+
opt :tls_ca_cert, "Trusted CA Certificate when using TLS", :type => String
|
41
|
+
opt :tls_verify, "Verify TLS peer when using TLS", :default => true
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
@@ -73,9 +78,14 @@ module Riemann
|
|
73
78
|
r = Riemann::Client.new(
|
74
79
|
:host => options[:host],
|
75
80
|
:port => options[:port],
|
76
|
-
:timeout => options[:timeout]
|
81
|
+
:timeout => options[:timeout],
|
82
|
+
:ssl => options[:tls],
|
83
|
+
:key_file => options[:tls_key],
|
84
|
+
:cert_file => options[:tls_cert],
|
85
|
+
:ca_file => options[:tls_ca_cert],
|
86
|
+
:ssl_verify => options[:tls_verify],
|
77
87
|
)
|
78
|
-
if options[:tcp]
|
88
|
+
if options[:tcp] || options[:tls]
|
79
89
|
r.tcp
|
80
90
|
else
|
81
91
|
r
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/riemann/tools/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'riemann-tools'
|
7
|
+
spec.version = Riemann::Tools::VERSION
|
8
|
+
spec.authors = ['Kyle Kingsbury']
|
9
|
+
spec.email = ['aphyr@aphyr.com']
|
10
|
+
|
11
|
+
spec.summary = 'Utilities which submit events to Riemann.'
|
12
|
+
spec.description = 'Collection of utilities which submit events to Riemann,'
|
13
|
+
spec.homepage = 'https://github.com/aphyr/riemann-tools'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
16
|
+
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'bin'
|
29
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'json', '>= 1.8'
|
33
|
+
spec.add_runtime_dependency 'optimist', '~> 3.0', '>= 3.0.0'
|
34
|
+
spec.add_runtime_dependency 'riemann-client', '~> 1.0'
|
35
|
+
|
36
|
+
spec.add_development_dependency 'github_changelog_generator'
|
37
|
+
spec.add_development_dependency 'rake'
|
38
|
+
spec.add_development_dependency 'rspec'
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Kyle Kingsbury
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Riemann AWS tools
|
2
|
+
|
3
|
+
Gathers various AWS services statistics and submits them to Riemann.
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install riemann-aws
|
9
|
+
```
|
10
|
+
|
11
|
+
## AWS Commands
|
12
|
+
|
13
|
+
|
14
|
+
### Riemann AWS Billing
|
15
|
+
|
16
|
+
```
|
17
|
+
riemann-aws-billing --help
|
18
|
+
```
|
19
|
+
|
20
|
+
### Riemann AWS RDS Status
|
21
|
+
|
22
|
+
```
|
23
|
+
riemann-aws-rds-status --help
|
24
|
+
```
|
25
|
+
|
26
|
+
### Riemann AWS SQS Status
|
27
|
+
|
28
|
+
```
|
29
|
+
riemann-aws-sqs-status --help
|
30
|
+
```
|
31
|
+
|
32
|
+
### Riemann AWS Status
|
33
|
+
|
34
|
+
```
|
35
|
+
riemann-aws-status --help
|
36
|
+
```
|
37
|
+
|
38
|
+
### Riemann ELB Metrics
|
39
|
+
|
40
|
+
```
|
41
|
+
riemann-elb-metrics --help
|
42
|
+
```
|
43
|
+
|
44
|
+
### Riemann S3 Status by asking Cloudwatch
|
45
|
+
|
46
|
+
```
|
47
|
+
riemann-s3-status --help
|
48
|
+
```
|
49
|
+
|
50
|
+
### Riemann S3 Count by listing objects
|
51
|
+
|
52
|
+
```
|
53
|
+
riemann-s3-list --help
|
54
|
+
```
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
require 'rdoc/task'
|
4
|
+
require 'find'
|
5
|
+
|
6
|
+
# Don't include resource forks in tarballs on Mac OS X.
|
7
|
+
ENV['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
|
8
|
+
ENV['COPYFILE_DISABLE'] = 'true'
|
9
|
+
|
10
|
+
# Gemspec
|
11
|
+
gemspec = Gem::Specification.new do |s|
|
12
|
+
s.rubyforge_project = 'riemann-aws'
|
13
|
+
|
14
|
+
s.name = 'riemann-aws'
|
15
|
+
s.version = '0.1.4'
|
16
|
+
s.author = 'Kyle Kingsbury'
|
17
|
+
s.email = 'aphyr@aphyr.com'
|
18
|
+
s.homepage = 'https://github.com/riemann/riemann-tools'
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.summary = 'Submits AWS stats to riemann.'
|
21
|
+
s.license = 'MIT'
|
22
|
+
|
23
|
+
s.add_dependency 'riemann-tools', '>= 0.2.13'
|
24
|
+
s.add_dependency 'fog', '>= 1.4.0'
|
25
|
+
s.add_dependency 'json'
|
26
|
+
|
27
|
+
s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
|
28
|
+
s.executables |= Dir.entries('bin/')
|
29
|
+
s.has_rdoc = false
|
30
|
+
|
31
|
+
s.required_ruby_version = '>= 1.8.7'
|
32
|
+
end
|
33
|
+
|
34
|
+
Gem::PackageTask.new gemspec do |p|
|
35
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
3
|
+
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
$0 = __FILE__
|
7
|
+
|
8
|
+
class Riemann::Tools::AWSBilling
|
9
|
+
include Riemann::Tools
|
10
|
+
require 'fog'
|
11
|
+
|
12
|
+
opt :fog_credentials_file, "Fog credentials file", :type => String
|
13
|
+
opt :fog_credential, "Fog credentials to use", :type => String
|
14
|
+
|
15
|
+
opt :access_key, "AWS access key", :type => String
|
16
|
+
opt :secret_key, "Secret access key", :type => String
|
17
|
+
opt :services, "AWS services: AmazonEC2 AmazonS3 AWSDataTransfer", :type => :strings, :multi => true, :default => ["AmazonEC2", "AmazonS3", "AWSDataTransfer"]
|
18
|
+
|
19
|
+
opt :time_start, "Start time in seconds of the metrics period (2hrs ago default)", :type => Integer, :default => 7200
|
20
|
+
opt :time_end, "End time in seconds of the metrics period ", :type => Integer, :default => 60
|
21
|
+
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
if options[:fog_credentials_file]
|
25
|
+
Fog.credentials_path = opts[:fog_credentials_file]
|
26
|
+
Fog.credential = opts[:fog_credential].to_sym
|
27
|
+
@cloudwatch = Fog::AWS::CloudWatch.new
|
28
|
+
else
|
29
|
+
if opts.has_key?('secret_key') and opts.has_key?('access_key')
|
30
|
+
creds = {
|
31
|
+
:aws_secret_access_key => opts[:secret_key],
|
32
|
+
:aws_access_key_id => opts[:access_key]
|
33
|
+
}
|
34
|
+
else
|
35
|
+
creds = { :use_iam_profile => true }
|
36
|
+
end
|
37
|
+
@cloudwatch = Fog::AWS::CloudWatch.new(creds)
|
38
|
+
end
|
39
|
+
@start_time = (Time.now.utc - opts[:time_start]).iso8601
|
40
|
+
@end_time = (Time.now.utc - opts[:time_end]).iso8601
|
41
|
+
end
|
42
|
+
|
43
|
+
def tick
|
44
|
+
opts[:services].each do |service|
|
45
|
+
data = @cloudwatch.get_metric_statistics({
|
46
|
+
'Statistics' => ["Maximum"],
|
47
|
+
'StartTime' => @start_time,
|
48
|
+
'EndTime' => @end_time,
|
49
|
+
'Period' => 3600,
|
50
|
+
'Unit' => "None",
|
51
|
+
'MetricName' => "EstimatedCharges",
|
52
|
+
'Namespace' => "AWS/Billing",
|
53
|
+
'Dimensions' => [
|
54
|
+
{
|
55
|
+
'Name' => "ServiceName",
|
56
|
+
'Value' => service
|
57
|
+
},
|
58
|
+
{
|
59
|
+
'Name' => "Currency",
|
60
|
+
'Value' => "USD"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
}).body['GetMetricStatisticsResult']['Datapoints']
|
64
|
+
|
65
|
+
|
66
|
+
data.each do |metrics|
|
67
|
+
name = "AWScloudwatch.Billing." + service
|
68
|
+
value = metrics["Maximum"]
|
69
|
+
timestamp = metrics["Timestamp"].to_i
|
70
|
+
|
71
|
+
event = {
|
72
|
+
host: nil,
|
73
|
+
service: name,
|
74
|
+
time: timestamp,
|
75
|
+
description: "AWS Estimate Charges for #{service}",
|
76
|
+
tags: ["aws_billing"],
|
77
|
+
state: "ok",
|
78
|
+
metric: value
|
79
|
+
}
|
80
|
+
|
81
|
+
report event
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
Riemann::Tools::AWSBilling.run
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
3
|
+
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
$0 = __FILE__ # Let's not expose our AWS keys in the process list
|
7
|
+
|
8
|
+
class Riemann::Tools::AWS
|
9
|
+
include Riemann::Tools
|
10
|
+
require 'fog'
|
11
|
+
require 'date'
|
12
|
+
require 'time'
|
13
|
+
require 'json'
|
14
|
+
|
15
|
+
opt :access_key, "AWS access key", :type => String
|
16
|
+
opt :secret_key, "Secret access key", :type => String
|
17
|
+
opt :region, "AWS region", :type => String, :default => 'eu-west-1'
|
18
|
+
opt :dbinstance_identifier, "DBInstanceIdentifier", :type => String
|
19
|
+
def initialize
|
20
|
+
abort "FATAL: specify a DB instance name, see --help for usage" unless opts[:dbinstance_identifier]
|
21
|
+
if opts[:access_key] and opts[:secret_key]
|
22
|
+
creds = {
|
23
|
+
:aws_access_key_id => opts[:access_key],
|
24
|
+
:aws_secret_access_key => opts[:secret_key]
|
25
|
+
}
|
26
|
+
else
|
27
|
+
creds = { :use_iam_profile => true }
|
28
|
+
end
|
29
|
+
creds['region'] = opts[:region]
|
30
|
+
@cloudwatch = Fog::AWS::CloudWatch.new(creds)
|
31
|
+
end
|
32
|
+
|
33
|
+
def tick
|
34
|
+
time = Time.new
|
35
|
+
['DatabaseConnections', 'FreeableMemory', 'FreeStorageSpace', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput', 'ReadThroughput', 'CPUUtilization'].each do |metric|
|
36
|
+
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})
|
37
|
+
metricsResult = result.data[:body]['GetMetricStatisticsResult']
|
38
|
+
if (metricsResult['Datapoints'].length>0)
|
39
|
+
datapoint = metricsResult['Datapoints'][0]
|
40
|
+
ev = {:metric => datapoint['Average'],
|
41
|
+
:service => "#{opts[:dbinstance_identifier]}.#{metric} (#{datapoint['Unit']})",
|
42
|
+
:description => JSON.dump(metricsResult),
|
43
|
+
:state => "ok",
|
44
|
+
:ttl => 300}
|
45
|
+
|
46
|
+
|
47
|
+
report ev
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Riemann::Tools::AWS.run
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
Process.setproctitle($0)
|
3
|
+
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
$0 = __FILE__ # Let's not expose our AWS keys in the process list
|
7
|
+
|
8
|
+
class Riemann::Tools::AWS
|
9
|
+
include Riemann::Tools
|
10
|
+
require 'fog'
|
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 :queue, "SQS Queue name", :type => String
|
16
|
+
def initialize
|
17
|
+
if opts.has_key?('access_key') and opts.has_key?('secret_key')
|
18
|
+
creds = {
|
19
|
+
:aws_access_key_id => opts[:access_key],
|
20
|
+
:aws_secret_access_key => opts[:secret_key]
|
21
|
+
}
|
22
|
+
else
|
23
|
+
creds = { :use_iam_profile => true }
|
24
|
+
end
|
25
|
+
creds['region'] = opts[:region]
|
26
|
+
@sqs = Fog::AWS::SQS.new(creds)
|
27
|
+
response = @sqs.list_queues({'QueueNamePrefix' => opts[:queue]})
|
28
|
+
@queue_url = response[:body]['QueueUrls'].first
|
29
|
+
end
|
30
|
+
|
31
|
+
def tick
|
32
|
+
response = @sqs.get_queue_attributes(@queue_url, 'All')
|
33
|
+
['ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible'].each do |attr|
|
34
|
+
msg = {
|
35
|
+
metric: response[:body]['Attributes'][attr],
|
36
|
+
service: "#{opts[:queue]} #{attr}",
|
37
|
+
state: 'ok'
|
38
|
+
}
|
39
|
+
report msg
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
Riemann::Tools::AWS.run
|