riemann-tools 1.1.1 → 1.2.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 +25 -2
- data/Rakefile +10 -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-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 +75 -0
- data/bin/riemann-zookeeper +1 -39
- 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/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.rb +2 -20
- data/riemann-tools.gemspec +4 -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 +57 -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
@@ -3,161 +3,6 @@
|
|
3
3
|
|
4
4
|
Process.setproctitle($PROGRAM_NAME)
|
5
5
|
|
6
|
-
require 'riemann/tools'
|
6
|
+
require 'riemann/tools/marathon'
|
7
7
|
|
8
|
-
module Riemann
|
9
|
-
module Tools
|
10
|
-
class Marathon
|
11
|
-
include Riemann::Tools
|
12
|
-
|
13
|
-
require 'faraday'
|
14
|
-
require 'json'
|
15
|
-
require 'uri'
|
16
|
-
|
17
|
-
opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
|
18
|
-
opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
|
19
|
-
opt :path_prefix,
|
20
|
-
'Marathon path prefix for proxied installations e.g. "marathon" for target http://localhost/marathon/metrics', default: '/'
|
21
|
-
opt :marathon_host, 'Marathon host', default: 'localhost'
|
22
|
-
opt :marathon_port, 'Marathon port', type: :int, default: 8080
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
options[:interval] = 60
|
26
|
-
options[:ttl] = 120
|
27
|
-
end
|
28
|
-
|
29
|
-
# Handles HTTP connections and GET requests safely
|
30
|
-
def safe_get(uri)
|
31
|
-
# Handle connection timeouts
|
32
|
-
response = nil
|
33
|
-
begin
|
34
|
-
connection = Faraday.new(uri)
|
35
|
-
response = connection.get do |req|
|
36
|
-
req.options[:timeout] = options[:read_timeout]
|
37
|
-
req.options[:open_timeout] = options[:open_timeout]
|
38
|
-
end
|
39
|
-
rescue StandardError => e
|
40
|
-
report(
|
41
|
-
host: uri.host,
|
42
|
-
service: 'marathon health',
|
43
|
-
state: 'critical',
|
44
|
-
description: "HTTP connection error: #{e.class} - #{e.message}",
|
45
|
-
)
|
46
|
-
end
|
47
|
-
response
|
48
|
-
end
|
49
|
-
|
50
|
-
def health_url
|
51
|
-
path_prefix = options[:path_prefix]
|
52
|
-
path_prefix[0] = '' if path_prefix[0] == '/'
|
53
|
-
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
54
|
-
"http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics"
|
55
|
-
end
|
56
|
-
|
57
|
-
def apps_url
|
58
|
-
path_prefix = options[:path_prefix]
|
59
|
-
path_prefix[0] = '' if path_prefix[0] == '/'
|
60
|
-
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
61
|
-
"http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/v2/apps"
|
62
|
-
end
|
63
|
-
|
64
|
-
def tick
|
65
|
-
tick_health
|
66
|
-
tick_apps
|
67
|
-
end
|
68
|
-
|
69
|
-
def tick_health
|
70
|
-
uri = URI(health_url)
|
71
|
-
response = safe_get(uri)
|
72
|
-
|
73
|
-
return if response.nil?
|
74
|
-
|
75
|
-
if response.status != 200
|
76
|
-
report(
|
77
|
-
host: uri.host,
|
78
|
-
service: 'marathon health',
|
79
|
-
state: 'critical',
|
80
|
-
description: "HTTP connection error: #{response.status} - #{response.body}",
|
81
|
-
)
|
82
|
-
else
|
83
|
-
# Assuming that a 200 will give json
|
84
|
-
json = JSON.parse(response.body)
|
85
|
-
state = 'ok'
|
86
|
-
|
87
|
-
report(
|
88
|
-
host: uri.host,
|
89
|
-
service: 'marathon health',
|
90
|
-
state: state,
|
91
|
-
)
|
92
|
-
|
93
|
-
json.each_pair do |t, d|
|
94
|
-
next unless d.respond_to? :each_pair
|
95
|
-
|
96
|
-
d.each_pair do |service, counters|
|
97
|
-
report(
|
98
|
-
host: uri.host,
|
99
|
-
service: "marathon_metric #{t} #{service}",
|
100
|
-
metric: 1,
|
101
|
-
tags: ['metric_name'],
|
102
|
-
ttl: 600,
|
103
|
-
)
|
104
|
-
next unless counters.respond_to? :each_pair
|
105
|
-
|
106
|
-
counters.each_pair do |k, v|
|
107
|
-
next unless v.is_a? Numeric
|
108
|
-
|
109
|
-
report(
|
110
|
-
host: uri.host,
|
111
|
-
service: "marathon #{service} #{k}",
|
112
|
-
metric: v,
|
113
|
-
tags: ['metric', t.to_s],
|
114
|
-
ttl: 600,
|
115
|
-
)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def tick_apps
|
123
|
-
uri = URI(apps_url)
|
124
|
-
response = safe_get(uri)
|
125
|
-
|
126
|
-
return if response.nil?
|
127
|
-
|
128
|
-
if response.status != 200
|
129
|
-
report(
|
130
|
-
host: uri.host,
|
131
|
-
service: 'marathon health',
|
132
|
-
state: 'critical',
|
133
|
-
description: "HTTP connection error: #{response.status} - #{response.body}",
|
134
|
-
)
|
135
|
-
else
|
136
|
-
# Assuming that a 200 will give json
|
137
|
-
json = JSON.parse(response.body)
|
138
|
-
state = 'ok'
|
139
|
-
|
140
|
-
report(
|
141
|
-
host: uri.host,
|
142
|
-
service: 'marathon health',
|
143
|
-
state: state,
|
144
|
-
)
|
145
|
-
|
146
|
-
json['apps'].each do |app|
|
147
|
-
app.each_pair do |k, v|
|
148
|
-
next unless v.is_a? Numeric
|
149
|
-
|
150
|
-
report(
|
151
|
-
host: uri.host,
|
152
|
-
service: "marathon apps#{app['id']}/#{k}",
|
153
|
-
metric: v,
|
154
|
-
ttl: 120,
|
155
|
-
)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
8
|
Riemann::Tools::Marathon.run
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Tools
|
7
|
+
class Marathon
|
8
|
+
include Riemann::Tools
|
9
|
+
|
10
|
+
require 'faraday'
|
11
|
+
require 'json'
|
12
|
+
require 'uri'
|
13
|
+
|
14
|
+
opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
|
15
|
+
opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
|
16
|
+
opt :path_prefix,
|
17
|
+
'Marathon path prefix for proxied installations e.g. "marathon" for target http://localhost/marathon/metrics', default: '/'.dup
|
18
|
+
opt :marathon_host, 'Marathon host', default: 'localhost'
|
19
|
+
opt :marathon_port, 'Marathon port', type: :int, default: 8080
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
options[:interval] = 60
|
23
|
+
options[:ttl] = 120
|
24
|
+
end
|
25
|
+
|
26
|
+
# Handles HTTP connections and GET requests safely
|
27
|
+
def safe_get(uri)
|
28
|
+
# Handle connection timeouts
|
29
|
+
response = nil
|
30
|
+
begin
|
31
|
+
connection = Faraday.new(uri)
|
32
|
+
response = connection.get do |req|
|
33
|
+
req.options[:timeout] = options[:read_timeout]
|
34
|
+
req.options[:open_timeout] = options[:open_timeout]
|
35
|
+
end
|
36
|
+
rescue StandardError => e
|
37
|
+
report(
|
38
|
+
host: uri.host,
|
39
|
+
service: 'marathon health',
|
40
|
+
state: 'critical',
|
41
|
+
description: "HTTP connection error: #{e.class} - #{e.message}",
|
42
|
+
)
|
43
|
+
end
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
def health_url
|
48
|
+
path_prefix = options[:path_prefix]
|
49
|
+
path_prefix[0] = '' if path_prefix[0] == '/'
|
50
|
+
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
51
|
+
"http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics"
|
52
|
+
end
|
53
|
+
|
54
|
+
def apps_url
|
55
|
+
path_prefix = options[:path_prefix]
|
56
|
+
path_prefix[0] = '' if path_prefix[0] == '/'
|
57
|
+
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
58
|
+
"http://#{options[:marathon_host]}:#{options[:marathon_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/v2/apps"
|
59
|
+
end
|
60
|
+
|
61
|
+
def tick
|
62
|
+
tick_health
|
63
|
+
tick_apps
|
64
|
+
end
|
65
|
+
|
66
|
+
def tick_health
|
67
|
+
uri = URI(health_url)
|
68
|
+
response = safe_get(uri)
|
69
|
+
|
70
|
+
return if response.nil?
|
71
|
+
|
72
|
+
if response.status != 200
|
73
|
+
report(
|
74
|
+
host: uri.host,
|
75
|
+
service: 'marathon health',
|
76
|
+
state: 'critical',
|
77
|
+
description: "HTTP connection error: #{response.status} - #{response.body}",
|
78
|
+
)
|
79
|
+
else
|
80
|
+
# Assuming that a 200 will give json
|
81
|
+
json = JSON.parse(response.body)
|
82
|
+
state = 'ok'
|
83
|
+
|
84
|
+
report(
|
85
|
+
host: uri.host,
|
86
|
+
service: 'marathon health',
|
87
|
+
state: state,
|
88
|
+
)
|
89
|
+
|
90
|
+
json.each_pair do |t, d|
|
91
|
+
next unless d.respond_to? :each_pair
|
92
|
+
|
93
|
+
d.each_pair do |service, counters|
|
94
|
+
report(
|
95
|
+
host: uri.host,
|
96
|
+
service: "marathon_metric #{t} #{service}",
|
97
|
+
metric: 1,
|
98
|
+
tags: ['metric_name'],
|
99
|
+
ttl: 600,
|
100
|
+
)
|
101
|
+
next unless counters.respond_to? :each_pair
|
102
|
+
|
103
|
+
counters.each_pair do |k, v|
|
104
|
+
next unless v.is_a? Numeric
|
105
|
+
|
106
|
+
report(
|
107
|
+
host: uri.host,
|
108
|
+
service: "marathon #{service} #{k}",
|
109
|
+
metric: v,
|
110
|
+
tags: ['metric', t.to_s],
|
111
|
+
ttl: 600,
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def tick_apps
|
120
|
+
uri = URI(apps_url)
|
121
|
+
response = safe_get(uri)
|
122
|
+
|
123
|
+
return if response.nil?
|
124
|
+
|
125
|
+
if response.status != 200
|
126
|
+
report(
|
127
|
+
host: uri.host,
|
128
|
+
service: 'marathon health',
|
129
|
+
state: 'critical',
|
130
|
+
description: "HTTP connection error: #{response.status} - #{response.body}",
|
131
|
+
)
|
132
|
+
else
|
133
|
+
# Assuming that a 200 will give json
|
134
|
+
json = JSON.parse(response.body)
|
135
|
+
state = 'ok'
|
136
|
+
|
137
|
+
report(
|
138
|
+
host: uri.host,
|
139
|
+
service: 'marathon health',
|
140
|
+
state: state,
|
141
|
+
)
|
142
|
+
|
143
|
+
json['apps'].each do |app|
|
144
|
+
app.each_pair do |k, v|
|
145
|
+
next unless v.is_a? Numeric
|
146
|
+
|
147
|
+
report(
|
148
|
+
host: uri.host,
|
149
|
+
service: "marathon apps#{app['id']}/#{k}",
|
150
|
+
metric: v,
|
151
|
+
ttl: 120,
|
152
|
+
)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -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-mesos'
|
15
|
-
|
16
14
|
s.name = 'riemann-mesos'
|
17
|
-
s.version = '0.1.
|
15
|
+
s.version = '0.1.4'
|
18
16
|
s.author = 'Giulio Eulisse'
|
19
17
|
s.email = 'giulio.eulisse@cern.ch'
|
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 mesos 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 'faraday', '~> 2.3', '>= 2.3.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,144 +3,6 @@
|
|
3
3
|
|
4
4
|
Process.setproctitle($PROGRAM_NAME)
|
5
5
|
|
6
|
-
require 'riemann/tools'
|
6
|
+
require 'riemann/tools/mesos'
|
7
7
|
|
8
|
-
module Riemann
|
9
|
-
module Tools
|
10
|
-
class Mesos
|
11
|
-
include Riemann::Tools
|
12
|
-
|
13
|
-
require 'faraday'
|
14
|
-
require 'json'
|
15
|
-
require 'uri'
|
16
|
-
|
17
|
-
opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
|
18
|
-
opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
|
19
|
-
opt :path_prefix,
|
20
|
-
'Mesos path prefix for proxied installations e.g. "mesos" for target http://localhost/mesos/metrics/snapshot', default: '/'
|
21
|
-
opt :mesos_host, 'Mesos host', default: 'localhost'
|
22
|
-
opt :mesos_port, 'Mesos port', type: :int, default: 5050
|
23
|
-
|
24
|
-
# Handles HTTP connections and GET requests safely
|
25
|
-
def safe_get(uri)
|
26
|
-
# Handle connection timeouts
|
27
|
-
response = nil
|
28
|
-
begin
|
29
|
-
connection = Faraday.new(uri)
|
30
|
-
response = connection.get do |req|
|
31
|
-
req.options[:timeout] = options[:read_timeout]
|
32
|
-
req.options[:open_timeout] = options[:open_timeout]
|
33
|
-
end
|
34
|
-
rescue StandardError => e
|
35
|
-
report(
|
36
|
-
host: uri.host,
|
37
|
-
service: 'mesos health',
|
38
|
-
state: 'critical',
|
39
|
-
description: "HTTP connection error: #{e.class} - #{e.message}",
|
40
|
-
)
|
41
|
-
end
|
42
|
-
response
|
43
|
-
end
|
44
|
-
|
45
|
-
def health_url
|
46
|
-
path_prefix = options[:path_prefix]
|
47
|
-
path_prefix[0] = '' if path_prefix[0] == '/'
|
48
|
-
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
49
|
-
"http://#{options[:mesos_host]}:#{options[:mesos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics/snapshot"
|
50
|
-
end
|
51
|
-
|
52
|
-
def slaves_url
|
53
|
-
path_prefix = options[:path_prefix]
|
54
|
-
path_prefix[0] = '' if path_prefix[0] == '/'
|
55
|
-
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
56
|
-
"http://#{options[:mesos_host]}:#{options[:mesos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/master/slaves"
|
57
|
-
end
|
58
|
-
|
59
|
-
def tick
|
60
|
-
tick_slaves
|
61
|
-
uri = URI(health_url)
|
62
|
-
response = safe_get(uri)
|
63
|
-
|
64
|
-
return if response.nil?
|
65
|
-
|
66
|
-
if response.status != 200
|
67
|
-
report(
|
68
|
-
host: uri.host,
|
69
|
-
service: 'mesos health',
|
70
|
-
state: 'critical',
|
71
|
-
description: "HTTP connection error: #{response.status} - #{response.body}",
|
72
|
-
)
|
73
|
-
else
|
74
|
-
# Assuming that a 200 will give json
|
75
|
-
json = JSON.parse(response.body)
|
76
|
-
state = 'ok'
|
77
|
-
|
78
|
-
report(
|
79
|
-
host: uri.host,
|
80
|
-
service: 'mesos health',
|
81
|
-
state: state,
|
82
|
-
)
|
83
|
-
|
84
|
-
json.each_pair do |k, v|
|
85
|
-
report(
|
86
|
-
host: uri.host,
|
87
|
-
service: "mesos #{k}",
|
88
|
-
metric: v,
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def tick_slaves
|
95
|
-
uri = URI(slaves_url)
|
96
|
-
response = safe_get(uri)
|
97
|
-
|
98
|
-
return if response.nil?
|
99
|
-
|
100
|
-
if response.status != 200
|
101
|
-
report(
|
102
|
-
host: uri.host,
|
103
|
-
service: 'mesos health',
|
104
|
-
state: 'critical',
|
105
|
-
description: "HTTP connection error: #{response.status} - #{response.body}",
|
106
|
-
)
|
107
|
-
else
|
108
|
-
# Assuming that a 200 will give json
|
109
|
-
json = JSON.parse(response.body)
|
110
|
-
state = 'ok'
|
111
|
-
|
112
|
-
report(
|
113
|
-
host: uri.host,
|
114
|
-
service: 'mesos health',
|
115
|
-
state: state,
|
116
|
-
)
|
117
|
-
|
118
|
-
json['slaves'].each do |slave|
|
119
|
-
next unless slave.respond_to? 'each_pair'
|
120
|
-
|
121
|
-
slave.each_pair do |k, v|
|
122
|
-
if v.respond_to? 'each_pair'
|
123
|
-
v.each_pair do |k1, v1|
|
124
|
-
next unless v1.is_a? Numeric
|
125
|
-
|
126
|
-
report(
|
127
|
-
host: slave['hostname'],
|
128
|
-
service: "mesos slave/#{k}/#{k1}",
|
129
|
-
metric: v1,
|
130
|
-
)
|
131
|
-
end
|
132
|
-
elsif v.is_a? Numeric
|
133
|
-
report(
|
134
|
-
host: slave['hostname'],
|
135
|
-
service: "mesos slave/#{k}",
|
136
|
-
metric: v,
|
137
|
-
)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
8
|
Riemann::Tools::Mesos.run
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Tools
|
7
|
+
class Mesos
|
8
|
+
include Riemann::Tools
|
9
|
+
|
10
|
+
require 'faraday'
|
11
|
+
require 'json'
|
12
|
+
require 'uri'
|
13
|
+
|
14
|
+
opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
|
15
|
+
opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
|
16
|
+
opt :path_prefix,
|
17
|
+
'Mesos path prefix for proxied installations e.g. "mesos" for target http://localhost/mesos/metrics/snapshot', default: '/'.dup
|
18
|
+
opt :mesos_host, 'Mesos host', default: 'localhost'
|
19
|
+
opt :mesos_port, 'Mesos port', type: :int, default: 5050
|
20
|
+
|
21
|
+
# Handles HTTP connections and GET requests safely
|
22
|
+
def safe_get(uri)
|
23
|
+
# Handle connection timeouts
|
24
|
+
response = nil
|
25
|
+
begin
|
26
|
+
connection = Faraday.new(uri)
|
27
|
+
response = connection.get do |req|
|
28
|
+
req.options[:timeout] = options[:read_timeout]
|
29
|
+
req.options[:open_timeout] = options[:open_timeout]
|
30
|
+
end
|
31
|
+
rescue StandardError => e
|
32
|
+
report(
|
33
|
+
host: uri.host,
|
34
|
+
service: 'mesos health',
|
35
|
+
state: 'critical',
|
36
|
+
description: "HTTP connection error: #{e.class} - #{e.message}",
|
37
|
+
)
|
38
|
+
end
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
def health_url
|
43
|
+
path_prefix = options[:path_prefix]
|
44
|
+
path_prefix[0] = '' if path_prefix[0] == '/'
|
45
|
+
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
46
|
+
"http://#{options[:mesos_host]}:#{options[:mesos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics/snapshot"
|
47
|
+
end
|
48
|
+
|
49
|
+
def slaves_url
|
50
|
+
path_prefix = options[:path_prefix]
|
51
|
+
path_prefix[0] = '' if path_prefix[0] == '/'
|
52
|
+
path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
|
53
|
+
"http://#{options[:mesos_host]}:#{options[:mesos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/master/slaves"
|
54
|
+
end
|
55
|
+
|
56
|
+
def tick
|
57
|
+
tick_slaves
|
58
|
+
uri = URI(health_url)
|
59
|
+
response = safe_get(uri)
|
60
|
+
|
61
|
+
return if response.nil?
|
62
|
+
|
63
|
+
if response.status != 200
|
64
|
+
report(
|
65
|
+
host: uri.host,
|
66
|
+
service: 'mesos health',
|
67
|
+
state: 'critical',
|
68
|
+
description: "HTTP connection error: #{response.status} - #{response.body}",
|
69
|
+
)
|
70
|
+
else
|
71
|
+
# Assuming that a 200 will give json
|
72
|
+
json = JSON.parse(response.body)
|
73
|
+
state = 'ok'
|
74
|
+
|
75
|
+
report(
|
76
|
+
host: uri.host,
|
77
|
+
service: 'mesos health',
|
78
|
+
state: state,
|
79
|
+
)
|
80
|
+
|
81
|
+
json.each_pair do |k, v|
|
82
|
+
report(
|
83
|
+
host: uri.host,
|
84
|
+
service: "mesos #{k}",
|
85
|
+
metric: v,
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def tick_slaves
|
92
|
+
uri = URI(slaves_url)
|
93
|
+
response = safe_get(uri)
|
94
|
+
|
95
|
+
return if response.nil?
|
96
|
+
|
97
|
+
if response.status != 200
|
98
|
+
report(
|
99
|
+
host: uri.host,
|
100
|
+
service: 'mesos health',
|
101
|
+
state: 'critical',
|
102
|
+
description: "HTTP connection error: #{response.status} - #{response.body}",
|
103
|
+
)
|
104
|
+
else
|
105
|
+
# Assuming that a 200 will give json
|
106
|
+
json = JSON.parse(response.body)
|
107
|
+
state = 'ok'
|
108
|
+
|
109
|
+
report(
|
110
|
+
host: uri.host,
|
111
|
+
service: 'mesos health',
|
112
|
+
state: state,
|
113
|
+
)
|
114
|
+
|
115
|
+
json['slaves'].each do |slave|
|
116
|
+
next unless slave.respond_to? 'each_pair'
|
117
|
+
|
118
|
+
slave.each_pair do |k, v|
|
119
|
+
if v.respond_to? 'each_pair'
|
120
|
+
v.each_pair do |k1, v1|
|
121
|
+
next unless v1.is_a? Numeric
|
122
|
+
|
123
|
+
report(
|
124
|
+
host: slave['hostname'],
|
125
|
+
service: "mesos slave/#{k}/#{k1}",
|
126
|
+
metric: v1,
|
127
|
+
)
|
128
|
+
end
|
129
|
+
elsif v.is_a? Numeric
|
130
|
+
report(
|
131
|
+
host: slave['hostname'],
|
132
|
+
service: "mesos slave/#{k}",
|
133
|
+
metric: v,
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -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-munin'
|
15
|
-
|
16
14
|
s.name = 'riemann-munin'
|
17
|
-
s.version = '0.1.
|
15
|
+
s.version = '0.1.4'
|
18
16
|
s.author = 'Kyle Kingsbury'
|
19
17
|
s.email = 'aphyr@aphyr.com'
|
20
18
|
s.homepage = 'https://github.com/riemann/riemann-tools'
|
@@ -22,14 +20,13 @@ gemspec = Gem::Specification.new do |s|
|
|
22
20
|
s.summary = 'Submits munin stats to riemann.'
|
23
21
|
s.license = 'MIT'
|
24
22
|
|
25
|
-
s.
|
26
|
-
s.
|
23
|
+
s.add_runtime_dependency 'riemann-tools', '~> 1.0', '>= 1.1.1'
|
24
|
+
s.add_runtime_dependency 'munin-ruby', '~> 0.2', '>= 0.2.5'
|
27
25
|
|
28
|
-
s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
|
26
|
+
s.files = FileList['bin/*', 'lib/**/*.rb', 'LICENSE', 'README.md'].to_a
|
29
27
|
s.executables |= Dir.entries('bin/')
|
30
|
-
s.has_rdoc = false
|
31
28
|
|
32
|
-
s.required_ruby_version = '>=
|
29
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
33
30
|
end
|
34
31
|
|
35
32
|
Gem::PackageTask.new gemspec do |p|
|