riemann-tools 1.1.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +60 -2
- data/Rakefile +17 -3
- data/bin/riemann-apache-status +1 -106
- data/bin/riemann-bench +2 -70
- data/bin/riemann-cloudant +1 -56
- data/bin/riemann-consul +1 -106
- data/bin/riemann-dir-files-count +1 -55
- data/bin/riemann-dir-space +1 -55
- data/bin/riemann-diskstats +1 -92
- data/bin/riemann-fd +2 -81
- data/bin/riemann-freeswitch +2 -119
- data/bin/riemann-haproxy +1 -58
- data/bin/riemann-health +0 -2
- data/bin/riemann-kvminstance +2 -22
- data/bin/riemann-md +8 -0
- data/bin/riemann-memcached +1 -37
- data/bin/riemann-net +0 -2
- data/bin/riemann-nginx-status +1 -85
- data/bin/riemann-ntp +0 -2
- data/bin/riemann-portcheck +1 -44
- data/bin/riemann-proc +1 -108
- data/bin/riemann-varnish +1 -54
- data/bin/riemann-wrapper +113 -0
- data/bin/riemann-zookeeper +1 -39
- data/bin/riemann-zpool +8 -0
- data/lib/riemann/tools/apache_status.rb +107 -0
- data/lib/riemann/tools/bench.rb +72 -0
- data/lib/riemann/tools/cloudant.rb +57 -0
- data/lib/riemann/tools/consul_health.rb +107 -0
- data/lib/riemann/tools/dir_files_count.rb +56 -0
- data/lib/riemann/tools/dir_space.rb +56 -0
- data/lib/riemann/tools/diskstats.rb +94 -0
- data/lib/riemann/tools/fd.rb +81 -0
- data/lib/riemann/tools/freeswitch.rb +119 -0
- data/lib/riemann/tools/haproxy.rb +59 -0
- data/lib/riemann/tools/health.rb +150 -19
- data/lib/riemann/tools/kvm.rb +23 -0
- data/lib/riemann/tools/md.rb +35 -0
- data/lib/riemann/tools/mdstat_parser.tab.rb +340 -0
- data/lib/riemann/tools/memcached.rb +38 -0
- data/lib/riemann/tools/net.rb +2 -1
- data/lib/riemann/tools/nginx_status.rb +86 -0
- data/lib/riemann/tools/ntp.rb +1 -0
- data/lib/riemann/tools/portcheck.rb +45 -0
- data/lib/riemann/tools/proc.rb +109 -0
- data/lib/riemann/tools/riemann_client_wrapper.rb +43 -0
- data/lib/riemann/tools/uptime_parser.tab.rb +323 -0
- data/lib/riemann/tools/varnish.rb +55 -0
- data/lib/riemann/tools/version.rb +1 -1
- data/lib/riemann/tools/zookeeper.rb +40 -0
- data/lib/riemann/tools/zpool.rb +40 -0
- data/lib/riemann/tools.rb +2 -20
- data/riemann-tools.gemspec +10 -1
- data/tools/riemann-aws/Rakefile +6 -9
- data/tools/riemann-aws/bin/riemann-aws-billing +2 -87
- data/tools/riemann-aws/bin/riemann-aws-rds-status +2 -62
- data/tools/riemann-aws/bin/riemann-aws-sqs-status +2 -44
- data/tools/riemann-aws/bin/riemann-aws-status +2 -77
- data/tools/riemann-aws/bin/riemann-elb-metrics +2 -162
- data/tools/riemann-aws/bin/riemann-s3-list +2 -81
- data/tools/riemann-aws/bin/riemann-s3-status +2 -96
- data/tools/riemann-aws/lib/riemann/tools/aws/billing.rb +87 -0
- data/tools/riemann-aws/lib/riemann/tools/aws/elb_metrics.rb +163 -0
- data/tools/riemann-aws/lib/riemann/tools/aws/rds_status.rb +63 -0
- data/tools/riemann-aws/lib/riemann/tools/aws/s3_list.rb +82 -0
- data/tools/riemann-aws/lib/riemann/tools/aws/s3_status.rb +97 -0
- data/tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb +45 -0
- data/tools/riemann-aws/lib/riemann/tools/aws/status.rb +74 -0
- data/tools/riemann-chronos/Rakefile +6 -9
- data/tools/riemann-chronos/bin/riemann-chronos +1 -154
- data/tools/riemann-chronos/lib/riemann/tools/chronos.rb +157 -0
- data/tools/riemann-docker/Rakefile +5 -8
- data/tools/riemann-docker/bin/riemann-docker +2 -200
- data/tools/riemann-docker/lib/riemann/tools/docker.rb +200 -0
- data/tools/riemann-elasticsearch/Rakefile +6 -9
- data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +1 -167
- data/tools/riemann-elasticsearch/lib/riemann/tools/elasticsearch.rb +170 -0
- data/tools/riemann-marathon/Rakefile +6 -9
- data/tools/riemann-marathon/bin/riemann-marathon +1 -156
- data/tools/riemann-marathon/lib/riemann/tools/marathon.rb +159 -0
- data/tools/riemann-mesos/Rakefile +6 -9
- data/tools/riemann-mesos/bin/riemann-mesos +1 -139
- data/tools/riemann-mesos/lib/riemann/tools/mesos.rb +142 -0
- data/tools/riemann-munin/Rakefile +5 -8
- data/tools/riemann-munin/bin/riemann-munin +1 -36
- data/tools/riemann-munin/lib/riemann/tools/munin.rb +37 -0
- data/tools/riemann-rabbitmq/Rakefile +6 -9
- data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +1 -266
- data/tools/riemann-rabbitmq/lib/riemann/tools/rabbitmq.rb +269 -0
- data/tools/riemann-riak/Rakefile +5 -8
- data/tools/riemann-riak/bin/riemann-riak +1 -316
- data/tools/riemann-riak/bin/riemann-riak-keys +0 -1
- data/tools/riemann-riak/bin/riemann-riak-ring +0 -1
- data/tools/riemann-riak/lib/riemann/tools/riak.rb +317 -0
- metadata +64 -10
- data/.travis.yml +0 -31
- data/tools/riemann-riak/riak_status/key_count.erl +0 -13
- data/tools/riemann-riak/riak_status/riak_status.rb +0 -152
- data/tools/riemann-riak/riak_status/ringready.erl +0 -9
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
# Reports varnish stats to Riemann.
|
7
|
+
module Riemann
|
8
|
+
module Tools
|
9
|
+
class Varnish
|
10
|
+
include Riemann::Tools
|
11
|
+
|
12
|
+
opt :varnish_host, 'Varnish hostname', default: `hostname`.chomp
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
cmd = 'varnishstat -V'
|
16
|
+
Open3.popen3(cmd) do |_stdin, _stdout, stderr, _wait_thr|
|
17
|
+
@ver = /varnishstat \(varnish-(\d+)/.match(stderr.read)[1].to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
@vstats = if @ver >= 4
|
21
|
+
['MAIN.sess_conn',
|
22
|
+
'MAIN.sess_drop ',
|
23
|
+
'MAIN.client_req',
|
24
|
+
'MAIN.cache_hit',
|
25
|
+
'MAIN.cache_miss',]
|
26
|
+
else
|
27
|
+
%w[client_conn
|
28
|
+
client_drop
|
29
|
+
client_req
|
30
|
+
cache_hit
|
31
|
+
cache_miss]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def tick
|
36
|
+
stats = if @ver >= 4
|
37
|
+
`varnishstat -1 -f #{@vstats.join(' -f ')}`
|
38
|
+
else
|
39
|
+
`varnishstat -1 -f #{@vstats.join(',')}`
|
40
|
+
end
|
41
|
+
stats.each_line do |stat|
|
42
|
+
m = stat.split
|
43
|
+
report(
|
44
|
+
host: opts[:varnish_host].dup,
|
45
|
+
service: "varnish #{m[0]}",
|
46
|
+
metric: m[1].to_f,
|
47
|
+
state: 'ok',
|
48
|
+
description: m[3..].join(' ').to_s,
|
49
|
+
tags: ['varnish'],
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
|
5
|
+
# Gathers zookeeper STATS and submits them to Riemann.
|
6
|
+
module Riemann
|
7
|
+
module Tools
|
8
|
+
class Zookeeper
|
9
|
+
include Riemann::Tools
|
10
|
+
require 'socket'
|
11
|
+
|
12
|
+
opt :zookeeper_host, 'Zookeeper hostname', default: 'localhost'
|
13
|
+
opt :zookeeper_port, 'Zookeeper port', default: 2181
|
14
|
+
|
15
|
+
def tick
|
16
|
+
sock = TCPSocket.new(opts[:zookeeper_host], opts[:zookeeper_port])
|
17
|
+
sock.sync = true
|
18
|
+
sock.print('mntr')
|
19
|
+
sock.flush
|
20
|
+
|
21
|
+
loop do
|
22
|
+
stats = sock.gets
|
23
|
+
|
24
|
+
break if stats.nil?
|
25
|
+
|
26
|
+
m = stats.match(/^(\w+)\t+(.*)/)
|
27
|
+
|
28
|
+
report(
|
29
|
+
host: opts[:zookeeper_host].dup,
|
30
|
+
service: "zookeeper #{m[1]}",
|
31
|
+
metric: m[2].to_f,
|
32
|
+
state: 'ok',
|
33
|
+
tags: ['zookeeper'],
|
34
|
+
)
|
35
|
+
end
|
36
|
+
sock.close
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
require 'riemann/tools'
|
6
|
+
|
7
|
+
module Riemann
|
8
|
+
module Tools
|
9
|
+
class Zpool
|
10
|
+
include Riemann::Tools
|
11
|
+
|
12
|
+
def tick
|
13
|
+
output, status = Open3.capture2e('zpool status -x')
|
14
|
+
|
15
|
+
state = if status.success?
|
16
|
+
case output
|
17
|
+
when "all pools are healthy\n" then 'ok'
|
18
|
+
when /state: (DEGRADED|FAULTED)/ then 'critical'
|
19
|
+
else
|
20
|
+
'warning'
|
21
|
+
end
|
22
|
+
else
|
23
|
+
'critical'
|
24
|
+
end
|
25
|
+
|
26
|
+
report(
|
27
|
+
service: 'zpool health',
|
28
|
+
description: output,
|
29
|
+
state: state,
|
30
|
+
)
|
31
|
+
rescue Errno::ENOENT => e
|
32
|
+
report(
|
33
|
+
service: 'zpool health',
|
34
|
+
description: e.message,
|
35
|
+
state: 'critical',
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/riemann/tools.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Riemann
|
4
4
|
module Tools
|
5
5
|
require 'optimist'
|
6
|
-
require 'riemann/
|
6
|
+
require 'riemann/tools/riemann_client_wrapper'
|
7
7
|
|
8
8
|
def self.included(base)
|
9
9
|
base.instance_eval do
|
@@ -72,26 +72,8 @@ module Riemann
|
|
72
72
|
riemann << event
|
73
73
|
end
|
74
74
|
|
75
|
-
def new_riemann_client
|
76
|
-
r = Riemann::Client.new(
|
77
|
-
host: options[:host],
|
78
|
-
port: options[:port],
|
79
|
-
timeout: options[:timeout],
|
80
|
-
ssl: options[:tls],
|
81
|
-
key_file: options[:tls_key],
|
82
|
-
cert_file: options[:tls_cert],
|
83
|
-
ca_file: options[:tls_ca_cert],
|
84
|
-
ssl_verify: options[:tls_verify],
|
85
|
-
)
|
86
|
-
if options[:tcp] || options[:tls]
|
87
|
-
r.tcp
|
88
|
-
else
|
89
|
-
r
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
75
|
def riemann
|
94
|
-
@riemann ||=
|
76
|
+
@riemann ||= RiemannClientWrapper.instance.configure(options)
|
95
77
|
end
|
96
78
|
alias r riemann
|
97
79
|
|
data/riemann-tools.gemspec
CHANGED
@@ -23,7 +23,15 @@ Gem::Specification.new do |spec|
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
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)/}) }
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } -
|
27
|
+
[
|
28
|
+
'lib/riemann/tools/mdstat_parser.y',
|
29
|
+
'lib/riemann/tools/uptime_parser.y',
|
30
|
+
] +
|
31
|
+
[
|
32
|
+
'lib/riemann/tools/mdstat_parser.tab.rb',
|
33
|
+
'lib/riemann/tools/uptime_parser.tab.rb',
|
34
|
+
]
|
27
35
|
end
|
28
36
|
spec.bindir = 'bin'
|
29
37
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -34,6 +42,7 @@ Gem::Specification.new do |spec|
|
|
34
42
|
spec.add_runtime_dependency 'riemann-client', '~> 1.0'
|
35
43
|
|
36
44
|
spec.add_development_dependency 'github_changelog_generator'
|
45
|
+
spec.add_development_dependency 'racc'
|
37
46
|
spec.add_development_dependency 'rake'
|
38
47
|
spec.add_development_dependency 'rspec'
|
39
48
|
spec.add_development_dependency 'rubocop'
|
data/tools/riemann-aws/Rakefile
CHANGED
@@ -11,10 +11,8 @@ ENV['COPYFILE_DISABLE'] = 'true'
|
|
11
11
|
|
12
12
|
# Gemspec
|
13
13
|
gemspec = Gem::Specification.new do |s|
|
14
|
-
s.rubyforge_project = 'riemann-aws'
|
15
|
-
|
16
14
|
s.name = 'riemann-aws'
|
17
|
-
s.version = '0.1.
|
15
|
+
s.version = '0.1.5'
|
18
16
|
s.author = 'Kyle Kingsbury'
|
19
17
|
s.email = 'aphyr@aphyr.com'
|
20
18
|
s.homepage = 'https://github.com/riemann/riemann-tools'
|
@@ -22,15 +20,14 @@ gemspec = Gem::Specification.new do |s|
|
|
22
20
|
s.summary = 'Submits AWS stats to riemann.'
|
23
21
|
s.license = 'MIT'
|
24
22
|
|
25
|
-
s.
|
26
|
-
s.
|
27
|
-
s.
|
23
|
+
s.add_runtime_dependency 'riemann-tools', '~> 1.0', '>= 1.1.1'
|
24
|
+
s.add_runtime_dependency 'fog-aws', '~> 3.14', '>= 3.14.0'
|
25
|
+
s.add_runtime_dependency 'json', '~> 2.6', '>=2.6.2'
|
28
26
|
|
29
|
-
s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
|
27
|
+
s.files = FileList['bin/*', 'lib/**/*.rb', 'LICENSE', 'README.md'].to_a
|
30
28
|
s.executables |= Dir.entries('bin/')
|
31
|
-
s.has_rdoc = false
|
32
29
|
|
33
|
-
s.required_ruby_version = '>=
|
30
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
34
31
|
end
|
35
32
|
|
36
33
|
Gem::PackageTask.new gemspec do |p|
|
@@ -3,91 +3,6 @@
|
|
3
3
|
|
4
4
|
Process.setproctitle($PROGRAM_NAME)
|
5
5
|
|
6
|
-
require 'riemann/tools'
|
6
|
+
require 'riemann/tools/aws/billing'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
module Riemann
|
11
|
-
module Tools
|
12
|
-
class AWSBilling
|
13
|
-
include Riemann::Tools
|
14
|
-
require 'fog'
|
15
|
-
|
16
|
-
opt :fog_credentials_file, 'Fog credentials file', type: String
|
17
|
-
opt :fog_credential, 'Fog credentials to use', type: String
|
18
|
-
|
19
|
-
opt :access_key, 'AWS access key', type: String
|
20
|
-
opt :secret_key, 'Secret access key', type: String
|
21
|
-
opt :services, 'AWS services: AmazonEC2 AmazonS3 AWSDataTransfer', type: :strings, multi: true,
|
22
|
-
default: %w[AmazonEC2 AmazonS3 AWSDataTransfer]
|
23
|
-
|
24
|
-
opt :time_start, 'Start time in seconds of the metrics period (2hrs ago default)', type: Integer,
|
25
|
-
default: 7200
|
26
|
-
opt :time_end, 'End time in seconds of the metrics period ', type: Integer, default: 60
|
27
|
-
|
28
|
-
def initialize
|
29
|
-
if options[:fog_credentials_file]
|
30
|
-
Fog.credentials_path = opts[:fog_credentials_file]
|
31
|
-
Fog.credential = opts[:fog_credential].to_sym
|
32
|
-
@cloudwatch = Fog::AWS::CloudWatch.new
|
33
|
-
else
|
34
|
-
creds = if opts.key?('secret_key') && opts.key?('access_key')
|
35
|
-
{
|
36
|
-
aws_secret_access_key: opts[:secret_key],
|
37
|
-
aws_access_key_id: opts[:access_key],
|
38
|
-
}
|
39
|
-
else
|
40
|
-
{ use_iam_profile: true }
|
41
|
-
end
|
42
|
-
@cloudwatch = Fog::AWS::CloudWatch.new(creds)
|
43
|
-
end
|
44
|
-
@start_time = (Time.now.utc - opts[:time_start]).iso8601
|
45
|
-
@end_time = (Time.now.utc - opts[:time_end]).iso8601
|
46
|
-
end
|
47
|
-
|
48
|
-
def tick
|
49
|
-
opts[:services].each do |service|
|
50
|
-
data = @cloudwatch.get_metric_statistics({
|
51
|
-
'Statistics' => ['Maximum'],
|
52
|
-
'StartTime' => @start_time,
|
53
|
-
'EndTime' => @end_time,
|
54
|
-
'Period' => 3600,
|
55
|
-
'Unit' => 'None',
|
56
|
-
'MetricName' => 'EstimatedCharges',
|
57
|
-
'Namespace' => 'AWS/Billing',
|
58
|
-
'Dimensions' => [
|
59
|
-
{
|
60
|
-
'Name' => 'ServiceName',
|
61
|
-
'Value' => service,
|
62
|
-
},
|
63
|
-
{
|
64
|
-
'Name' => 'Currency',
|
65
|
-
'Value' => 'USD',
|
66
|
-
},
|
67
|
-
],
|
68
|
-
}).body['GetMetricStatisticsResult']['Datapoints']
|
69
|
-
|
70
|
-
data.each do |metrics|
|
71
|
-
name = "AWScloudwatch.Billing.#{service}"
|
72
|
-
value = metrics['Maximum']
|
73
|
-
timestamp = metrics['Timestamp'].to_i
|
74
|
-
|
75
|
-
event = {
|
76
|
-
host: nil,
|
77
|
-
service: name,
|
78
|
-
time: timestamp,
|
79
|
-
description: "AWS Estimate Charges for #{service}",
|
80
|
-
tags: ['aws_billing'],
|
81
|
-
state: 'ok',
|
82
|
-
metric: value,
|
83
|
-
}
|
84
|
-
|
85
|
-
report event
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
Riemann::Tools::AWSBilling.run
|
8
|
+
Riemann::Tools::Aws::Billing.run
|
@@ -3,66 +3,6 @@
|
|
3
3
|
|
4
4
|
Process.setproctitle($PROGRAM_NAME)
|
5
5
|
|
6
|
-
require 'riemann/tools'
|
6
|
+
require 'riemann/tools/aws/rds_status'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
module Riemann
|
11
|
-
module Tools
|
12
|
-
class AWS
|
13
|
-
include Riemann::Tools
|
14
|
-
require 'fog'
|
15
|
-
require 'date'
|
16
|
-
require 'time'
|
17
|
-
require 'json'
|
18
|
-
|
19
|
-
opt :access_key, 'AWS access key', type: String
|
20
|
-
opt :secret_key, 'Secret access key', type: String
|
21
|
-
opt :region, 'AWS region', type: String, default: 'eu-west-1'
|
22
|
-
opt :dbinstance_identifier, 'DBInstanceIdentifier', type: String
|
23
|
-
def initialize
|
24
|
-
abort 'FATAL: specify a DB instance name, see --help for usage' unless opts[:dbinstance_identifier]
|
25
|
-
creds = if opts[:access_key] && opts[:secret_key]
|
26
|
-
{
|
27
|
-
aws_access_key_id: opts[:access_key],
|
28
|
-
aws_secret_access_key: opts[:secret_key],
|
29
|
-
}
|
30
|
-
else
|
31
|
-
{ use_iam_profile: true }
|
32
|
-
end
|
33
|
-
creds['region'] = opts[:region]
|
34
|
-
@cloudwatch = Fog::AWS::CloudWatch.new(creds)
|
35
|
-
end
|
36
|
-
|
37
|
-
def tick
|
38
|
-
time = Time.new
|
39
|
-
%w[DatabaseConnections FreeableMemory FreeStorageSpace NetworkReceiveThroughput
|
40
|
-
NetworkTransmitThroughput ReadThroughput CPUUtilization].each do |metric|
|
41
|
-
result = @cloudwatch.get_metric_statistics(
|
42
|
-
'Namespace' => 'AWS/RDS',
|
43
|
-
'MetricName' => metric.to_s,
|
44
|
-
'Statistics' => 'Average',
|
45
|
-
'Dimensions' => [{ 'Name' => 'DBInstanceIdentifier', 'Value' => opts[:dbinstance_identifier].to_s }],
|
46
|
-
'StartTime' => (time - 120).to_time.iso8601,
|
47
|
-
'EndTime' => time.to_time.iso8601, 'Period' => 60,
|
48
|
-
)
|
49
|
-
metrics_result = result.data[:body]['GetMetricStatisticsResult']
|
50
|
-
next unless metrics_result['Datapoints'].length.positive?
|
51
|
-
|
52
|
-
datapoint = metrics_result['Datapoints'][0]
|
53
|
-
ev = {
|
54
|
-
metric: datapoint['Average'],
|
55
|
-
service: "#{opts[:dbinstance_identifier]}.#{metric} (#{datapoint['Unit']})",
|
56
|
-
description: JSON.dump(metrics_result),
|
57
|
-
state: 'ok',
|
58
|
-
ttl: 300,
|
59
|
-
}
|
60
|
-
|
61
|
-
report ev
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
Riemann::Tools::AWS.run
|
8
|
+
Riemann::Tools::Aws::RdsStatus.run
|
@@ -3,48 +3,6 @@
|
|
3
3
|
|
4
4
|
Process.setproctitle($PROGRAM_NAME)
|
5
5
|
|
6
|
-
require 'riemann/tools'
|
6
|
+
require 'riemann/tools/aws/sqs_status'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
module Riemann
|
11
|
-
module Tools
|
12
|
-
class AWS
|
13
|
-
include Riemann::Tools
|
14
|
-
require 'fog'
|
15
|
-
|
16
|
-
opt :access_key, 'AWS access key', type: String
|
17
|
-
opt :secret_key, 'Secret access key', type: String
|
18
|
-
opt :region, 'AWS region', type: String, default: 'us-east-1'
|
19
|
-
opt :queue, 'SQS Queue name', type: String
|
20
|
-
def initialize
|
21
|
-
creds = if opts.key?('access_key') && opts.key?('secret_key')
|
22
|
-
{
|
23
|
-
aws_access_key_id: opts[:access_key],
|
24
|
-
aws_secret_access_key: opts[:secret_key],
|
25
|
-
}
|
26
|
-
else
|
27
|
-
{ use_iam_profile: true }
|
28
|
-
end
|
29
|
-
creds['region'] = opts[:region]
|
30
|
-
@sqs = Fog::AWS::SQS.new(creds)
|
31
|
-
response = @sqs.list_queues({ 'QueueNamePrefix' => opts[:queue] })
|
32
|
-
@queue_url = response[:body]['QueueUrls'].first
|
33
|
-
end
|
34
|
-
|
35
|
-
def tick
|
36
|
-
response = @sqs.get_queue_attributes(@queue_url, 'All')
|
37
|
-
%w[ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible].each do |attr|
|
38
|
-
msg = {
|
39
|
-
metric: response[:body]['Attributes'][attr],
|
40
|
-
service: "#{opts[:queue]} #{attr}",
|
41
|
-
state: 'ok',
|
42
|
-
}
|
43
|
-
report msg
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
Riemann::Tools::AWS.run
|
8
|
+
Riemann::Tools::Aws::SqsStatus.run
|
@@ -3,81 +3,6 @@
|
|
3
3
|
|
4
4
|
Process.setproctitle($PROGRAM_NAME)
|
5
5
|
|
6
|
-
require 'riemann/tools'
|
6
|
+
require 'riemann/tools/aws/status'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
module Riemann
|
11
|
-
module Tools
|
12
|
-
class AWS
|
13
|
-
include Riemann::Tools
|
14
|
-
require 'fog'
|
15
|
-
require 'date'
|
16
|
-
|
17
|
-
opt :access_key, 'AWS access key', type: String
|
18
|
-
opt :secret_key, 'Secret access key', type: String
|
19
|
-
opt :region, 'AWS region', type: String, default: 'eu-west-1'
|
20
|
-
|
21
|
-
opt :retirement_critical, 'Number of days before retirement. Defaults to 2', default: 2
|
22
|
-
opt :event_warning, 'Number of days before event. Defaults to nil (i.e. when the event appears)', default: nil
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
creds = if opts.key?('secret_key') && opts.key?('access_key')
|
26
|
-
{
|
27
|
-
aws_secret_access_key: opts[:secret_key],
|
28
|
-
aws_access_key_id: opts[:access_key],
|
29
|
-
}
|
30
|
-
else
|
31
|
-
{ use_iam_profile: true }
|
32
|
-
end
|
33
|
-
creds['region'] = opts[:region]
|
34
|
-
creds['provider'] = 'AWS'
|
35
|
-
@compute = Fog::Compute.new(creds)
|
36
|
-
end
|
37
|
-
|
38
|
-
def tick
|
39
|
-
# XXX: needs work:
|
40
|
-
# * instance_status and status seems unused
|
41
|
-
# * where is inject comming from
|
42
|
-
# It looks line the only needed line for the 2 next paragraph is the one that assigns hosts.
|
43
|
-
instance_status = @compute.describe_instance_status.body['instanceStatusSet']
|
44
|
-
status = instance_status.each_with_object({}) do |i, acc|
|
45
|
-
acc[i.delete('instanceId')] = i
|
46
|
-
end
|
47
|
-
|
48
|
-
hosts = @compute.servers.select { |s| s.state == 'running' }
|
49
|
-
inject([status, {}]) do |(astatus, acc), host|
|
50
|
-
acc[host.private_dns_name] = astatus.delete(host.id)
|
51
|
-
[astatus, acc]
|
52
|
-
end[1]
|
53
|
-
|
54
|
-
hosts.each do |host, host_status|
|
55
|
-
host_status['eventsSet'].each do |event|
|
56
|
-
before, _after = %w[notBefore notAfter].map { |k| Date.parse event[k].to_s if event[k] }
|
57
|
-
|
58
|
-
ev = {
|
59
|
-
host: host,
|
60
|
-
service: 'aws_instance_status',
|
61
|
-
description: "#{event['code']}\n\nstart #{event['notBefore']}\nend #{event['notAfter']}\n\n#{event['description']}",
|
62
|
-
state: 'ok',
|
63
|
-
ttl: 300,
|
64
|
-
}
|
65
|
-
|
66
|
-
ev2 = if (event['code'] == 'instance-retirement') &&
|
67
|
-
(Date.today >= before - opts[:retirement_critical])
|
68
|
-
{ state: 'critical' }
|
69
|
-
elsif opts[:event_warning] && (Date.today >= before - opts[:event_warning])
|
70
|
-
{ state: 'warning' }
|
71
|
-
else
|
72
|
-
{ state: 'warning' }
|
73
|
-
end
|
74
|
-
|
75
|
-
report ev.merge(ev2)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
Riemann::Tools::AWS.run
|
8
|
+
Riemann::Tools::Aws::Status.run
|