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,269 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Tools
|
7
|
+
class Rabbitmq
|
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
|
+
|
17
|
+
opt :monitor_user, 'RabbitMQ monitoring user', type: :string
|
18
|
+
opt :monitor_pass, 'RabbitMQ monitoring user password', type: :string
|
19
|
+
opt :monitor_port, 'RabbitMQ monitoring port', type: :int, default: 15_672
|
20
|
+
opt :monitor_host, 'RabbitMQ monitoring host', type: :string, default: 'localhost'
|
21
|
+
opt :monitor_use_tls, 'RabbitMQ use tls', type: :bool, default: false
|
22
|
+
|
23
|
+
opt :max_queue_size, 'max number of items in a queue that is acceptable', type: :int, default: 1_000_000
|
24
|
+
opt :ignore_max_size_queues, "A regular expression to match queues that shouldn't be size-checked", type: :string
|
25
|
+
|
26
|
+
opt :node, 'Specify a node to monitor', type: :strings
|
27
|
+
|
28
|
+
def base_url
|
29
|
+
protocol = 'http'
|
30
|
+
protocol = 'https' if options[:monitor_use_tls] && (options[:monitor_use_tls] == true)
|
31
|
+
"#{protocol}://#{options[:monitor_user]}:#{options[:monitor_pass]}@#{options[:monitor_host]}:#{options[:monitor_port]}/api"
|
32
|
+
end
|
33
|
+
|
34
|
+
def overview_url
|
35
|
+
"#{base_url}/overview"
|
36
|
+
end
|
37
|
+
|
38
|
+
def node_url(node)
|
39
|
+
"#{base_url}/nodes/#{node}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def queues_url
|
43
|
+
"#{base_url}/queues"
|
44
|
+
end
|
45
|
+
|
46
|
+
def event_host
|
47
|
+
options[:event_host] || :monitor_host
|
48
|
+
end
|
49
|
+
|
50
|
+
def safe_get(uri, event_host)
|
51
|
+
# Handle connection timeouts
|
52
|
+
response = nil
|
53
|
+
begin
|
54
|
+
connection = Faraday.new(uri)
|
55
|
+
response = connection.get do |req|
|
56
|
+
req.options[:timeout] = options[:read_timeout]
|
57
|
+
req.options[:open_timeout] = options[:open_timeout]
|
58
|
+
end
|
59
|
+
report(
|
60
|
+
host: event_host,
|
61
|
+
service: 'rabbitmq monitoring',
|
62
|
+
state: 'ok',
|
63
|
+
description: 'Monitoring operational',
|
64
|
+
)
|
65
|
+
rescue StandardError => e
|
66
|
+
report(
|
67
|
+
host: event_host,
|
68
|
+
service: 'rabbitmq monitoring',
|
69
|
+
state: 'critical',
|
70
|
+
description: "HTTP connection error: #{e.class} - #{e.message}",
|
71
|
+
)
|
72
|
+
end
|
73
|
+
response
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_queues
|
77
|
+
response = safe_get(queues_url, event_host)
|
78
|
+
max_size_check_filter = (Regexp.new(options[:ignore_max_size_queues]) if options[:ignore_max_size_queues])
|
79
|
+
|
80
|
+
return if response.nil?
|
81
|
+
|
82
|
+
if response.status != 200
|
83
|
+
report(
|
84
|
+
host: event_host,
|
85
|
+
service: 'rabbitmq.queue',
|
86
|
+
state: 'critical',
|
87
|
+
description: "HTTP connection error to /api/queues: #{response.status} - #{response.body}",
|
88
|
+
)
|
89
|
+
else
|
90
|
+
report(
|
91
|
+
host: event_host,
|
92
|
+
service: 'rabbitmq.queue',
|
93
|
+
state: 'ok',
|
94
|
+
description: 'HTTP connection ok',
|
95
|
+
)
|
96
|
+
|
97
|
+
json = JSON.parse(response.body)
|
98
|
+
|
99
|
+
json.each do |queue|
|
100
|
+
svc = "rabbitmq.queue.#{queue['vhost']}.#{queue['name']}"
|
101
|
+
errs = []
|
102
|
+
|
103
|
+
errs << 'Queue has jobs but no consumers' if !queue['messages_ready'].nil? && (queue['messages_ready']).positive? && (queue['consumers']).zero?
|
104
|
+
|
105
|
+
errs << "Queue has #{queue['messages_ready']} jobs" if (max_size_check_filter.nil? || queue['name'] !~ (max_size_check_filter)) && !queue['messages_ready'].nil? && (queue['messages_ready'] > options[:max_queue_size])
|
106
|
+
|
107
|
+
if errs.empty?
|
108
|
+
report(
|
109
|
+
host: event_host,
|
110
|
+
service: svc,
|
111
|
+
state: 'ok',
|
112
|
+
description: 'Queue is looking good',
|
113
|
+
)
|
114
|
+
else
|
115
|
+
report(
|
116
|
+
host: event_host,
|
117
|
+
service: svc,
|
118
|
+
state: 'critical',
|
119
|
+
description: errs.join('; '),
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
stats = (queue['message_stats'] || {}).merge(
|
124
|
+
'messages' => queue['messages'],
|
125
|
+
'messages_details' => queue['messages_details'],
|
126
|
+
'messages_ready' => queue['messages_ready'],
|
127
|
+
'messages_ready_details' => queue['messages_ready_details'],
|
128
|
+
'messages_unacknowledged' => queue['messages_unacknowledged'],
|
129
|
+
'messages_unacknowledged_details' => queue['messages_unacknowledged_details'],
|
130
|
+
'consumers' => queue['consumers'],
|
131
|
+
'memory' => queue['memory'],
|
132
|
+
)
|
133
|
+
|
134
|
+
stats.each_pair do |k, v|
|
135
|
+
service = "#{svc}.#{k}"
|
136
|
+
metric = if k =~ (/details$/) && !v.nil?
|
137
|
+
v['rate']
|
138
|
+
else
|
139
|
+
v
|
140
|
+
end
|
141
|
+
|
142
|
+
# TODO: Set state via thresholds which can be configured
|
143
|
+
|
144
|
+
report(
|
145
|
+
host: event_host,
|
146
|
+
service: service,
|
147
|
+
metric: metric,
|
148
|
+
description: 'RabbitMQ monitor',
|
149
|
+
)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def check_overview
|
156
|
+
uri = URI(overview_url)
|
157
|
+
response = safe_get(uri, event_host)
|
158
|
+
|
159
|
+
return if response.nil?
|
160
|
+
|
161
|
+
json = JSON.parse(response.body)
|
162
|
+
|
163
|
+
if response.status != 200
|
164
|
+
report(
|
165
|
+
host: event_host,
|
166
|
+
service: 'rabbitmq',
|
167
|
+
state: 'critical',
|
168
|
+
description: "HTTP connection error: #{response.status} - #{response.body}",
|
169
|
+
)
|
170
|
+
else
|
171
|
+
report(
|
172
|
+
host: event_host,
|
173
|
+
service: 'rabbitmq monitoring',
|
174
|
+
state: 'ok',
|
175
|
+
description: 'HTTP connection ok',
|
176
|
+
)
|
177
|
+
|
178
|
+
%w[message_stats queue_totals object_totals].each do |stat|
|
179
|
+
# NOTE: / BUG ?
|
180
|
+
# Brand new servers can have blank message stats. Is this ok?
|
181
|
+
# I can't decide.
|
182
|
+
next if json[stat].empty?
|
183
|
+
|
184
|
+
json[stat].each_pair do |k, v|
|
185
|
+
service = "rabbitmq.#{stat}.#{k}"
|
186
|
+
metric = if k =~ /details$/
|
187
|
+
v['rate']
|
188
|
+
else
|
189
|
+
v
|
190
|
+
end
|
191
|
+
|
192
|
+
# TODO: Set state via thresholds which can be configured
|
193
|
+
|
194
|
+
report(
|
195
|
+
host: event_host,
|
196
|
+
service: service,
|
197
|
+
metric: metric,
|
198
|
+
description: 'RabbitMQ monitor',
|
199
|
+
)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def check_node
|
206
|
+
opts[:node].each do |n|
|
207
|
+
uri = URI(node_url(n))
|
208
|
+
response = safe_get(uri, event_host)
|
209
|
+
|
210
|
+
break if response.nil?
|
211
|
+
|
212
|
+
if response.status != 200
|
213
|
+
if response.status == 404
|
214
|
+
report(
|
215
|
+
host: event_host,
|
216
|
+
service: "rabbitmq.node.#{n}",
|
217
|
+
state: 'critical',
|
218
|
+
description: 'Node was not found in the cluster',
|
219
|
+
)
|
220
|
+
else
|
221
|
+
report(
|
222
|
+
host: event_host,
|
223
|
+
service: "rabbitmq.node.#{n}",
|
224
|
+
state: 'critical',
|
225
|
+
description: "HTTP error: #{response.status} - #{response.body}",
|
226
|
+
)
|
227
|
+
end
|
228
|
+
break
|
229
|
+
end
|
230
|
+
|
231
|
+
json = JSON.parse(response.body)
|
232
|
+
|
233
|
+
if json['mem_alarm']
|
234
|
+
report(
|
235
|
+
host: event_host,
|
236
|
+
service: "rabbitmq.node.#{n}",
|
237
|
+
state: 'critical',
|
238
|
+
description: 'Memory alarm has triggered; job submission throttled',
|
239
|
+
)
|
240
|
+
break
|
241
|
+
end
|
242
|
+
|
243
|
+
if json['disk_free_alarm']
|
244
|
+
report(
|
245
|
+
host: event_host,
|
246
|
+
service: "rabbitmq.node.#{n}",
|
247
|
+
state: 'critical',
|
248
|
+
description: 'Disk free alarm has triggered; job submission throttled',
|
249
|
+
)
|
250
|
+
break
|
251
|
+
end
|
252
|
+
|
253
|
+
report(
|
254
|
+
host: event_host,
|
255
|
+
service: "rabbitmq.node.#{n}",
|
256
|
+
state: 'ok',
|
257
|
+
description: 'Node looks OK to me',
|
258
|
+
)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def tick
|
263
|
+
check_overview
|
264
|
+
check_node if opts[:node]
|
265
|
+
check_queues
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
data/tools/riemann-riak/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-riak'
|
15
|
-
|
16
14
|
s.name = 'riemann-riak'
|
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 riak 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 'yajl-ruby', '~> 1.4', '>= 1.4.3'
|
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|
|
@@ -1,323 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require 'English'
|
5
4
|
Process.setproctitle($PROGRAM_NAME)
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
require 'riemann/tools'
|
10
|
-
|
11
|
-
module Riemann
|
12
|
-
module Tools
|
13
|
-
class Riak
|
14
|
-
include Riemann::Tools
|
15
|
-
require 'net/http'
|
16
|
-
require 'net/https'
|
17
|
-
require 'yajl/json_gem'
|
18
|
-
|
19
|
-
opt :riak_host, 'Riak host for stats <IP> or SSL http(s)://<IP>', default: Socket.gethostname
|
20
|
-
opt :data_dir, 'Riak data directory', default: '/var/lib/riak'
|
21
|
-
opt :stats_port, 'Riak HTTP port for stats', default: 8098
|
22
|
-
opt :stats_path, 'Riak HTTP stats path', default: '/stats'
|
23
|
-
opt :node_name, 'Riak erlang node name', default: "riak@#{Socket.gethostname}"
|
24
|
-
opt :cookie, 'Riak cookie to use', default: 'riak'
|
25
|
-
|
26
|
-
opt :get_50_warning, 'FSM 50% get time warning threshold (ms)', default: 1000
|
27
|
-
opt :put_50_warning, 'FSM 50% put time warning threshold (ms)', default: 1000
|
28
|
-
opt :get_95_warning, 'FSM 95% get time warning threshold (ms)', default: 2000
|
29
|
-
opt :put_95_warning, 'FSM 95% put time warning threshold (ms)', default: 2000
|
30
|
-
opt :get_99_warning, 'FSM 99% get time warning threshold (ms)', default: 10_000
|
31
|
-
opt :put_99_warning, 'FSM 99% put time warning threshold (ms)', default: 10_000
|
32
|
-
|
33
|
-
def initialize
|
34
|
-
detect_features
|
35
|
-
|
36
|
-
@httpstatus = true
|
37
|
-
|
38
|
-
begin
|
39
|
-
uri = URI.parse(opts[:riak_host])
|
40
|
-
uri.host = opts[:riak_host] if uri.host.nil?
|
41
|
-
http = Net::HTTP.new(uri.host, opts[:stats_port])
|
42
|
-
http.use_ssl = uri.scheme == 'https'
|
43
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
44
|
-
http.start do |h|
|
45
|
-
h.get opts[:stats_path]
|
46
|
-
end
|
47
|
-
rescue StandardError => _e
|
48
|
-
@httpstatus = false
|
49
|
-
end
|
50
|
-
|
51
|
-
# we're going to override the emulator setting to allow users to
|
52
|
-
# dynamically input the cookie
|
53
|
-
# this is done only once - hopefully it doesn't get overridden.
|
54
|
-
ENV['ERL_AFLAGS'] = "-setcookie #{opts[:cookie]}"
|
55
|
-
end
|
56
|
-
|
57
|
-
# Identifies whether escript and riak-admin are installed
|
58
|
-
def detect_features
|
59
|
-
@escript = true # Whether escript is present on this machine
|
60
|
-
@riakadmin = true # Whether riak-admin is present
|
61
|
-
|
62
|
-
@escript = false if `which escript` =~ /^\s*$/
|
63
|
-
|
64
|
-
@riakadmin = false if `which riak-admin` =~ /^\s*$/
|
65
|
-
end
|
66
|
-
|
67
|
-
def check_ring
|
68
|
-
str = if @escript
|
69
|
-
`#{__dir__}/riemann-riak-ring #{opts[:node_name]}`.chomp
|
70
|
-
elsif @riakadmin
|
71
|
-
`riak-admin ringready`
|
72
|
-
end
|
73
|
-
|
74
|
-
return if str.nil?
|
75
|
-
|
76
|
-
if str =~ /^TRUE/
|
77
|
-
report(
|
78
|
-
host: opts[:riak_host],
|
79
|
-
service: 'riak ring',
|
80
|
-
state: 'ok',
|
81
|
-
description: str,
|
82
|
-
)
|
83
|
-
else
|
84
|
-
report(
|
85
|
-
host: opts[:riak_host],
|
86
|
-
service: 'riak ring',
|
87
|
-
state: 'warning',
|
88
|
-
description: str,
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def check_keys
|
94
|
-
keys = `#{__dir__}/riemann-riak-keys #{opts[:node_name]}`.chomp
|
95
|
-
if keys =~ /^\d+$/
|
96
|
-
report(
|
97
|
-
host: opts[:riak_host],
|
98
|
-
service: 'riak keys',
|
99
|
-
state: 'ok',
|
100
|
-
metric: keys.to_i,
|
101
|
-
description: keys,
|
102
|
-
)
|
103
|
-
else
|
104
|
-
report(
|
105
|
-
host: opts[:riak_host],
|
106
|
-
service: 'riak keys',
|
107
|
-
state: 'unknown',
|
108
|
-
description: keys,
|
109
|
-
)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def check_transfers
|
114
|
-
str = (`riak-admin transfers` if @riakadmin)
|
115
|
-
|
116
|
-
return if str.nil?
|
117
|
-
|
118
|
-
if str =~ /'#{opts[:node_name]}' waiting to handoff (\d+) partitions/
|
119
|
-
report(
|
120
|
-
host: opts[:riak_host],
|
121
|
-
service: 'riak transfers',
|
122
|
-
state: 'critical',
|
123
|
-
metric: Regexp.last_match(1).to_i,
|
124
|
-
description: "waiting to handoff #{Regexp.last_match(1)} partitions",
|
125
|
-
)
|
126
|
-
else
|
127
|
-
report(
|
128
|
-
host: opts[:riak_host],
|
129
|
-
service: 'riak transfers',
|
130
|
-
state: 'ok',
|
131
|
-
metric: 0,
|
132
|
-
description: 'No pending transfers',
|
133
|
-
)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def check_disk
|
138
|
-
gb = `du -Ls #{opts[:data_dir]}`.split(/\s+/).first.to_i / (1024.0**2)
|
139
|
-
report(
|
140
|
-
host: opts[:riak_host],
|
141
|
-
service: 'riak disk',
|
142
|
-
state: 'ok',
|
143
|
-
metric: gb,
|
144
|
-
description: "#{gb} GB in #{opts[:data_dir]}",
|
145
|
-
)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Returns the riak stat for the given fsm type and percentile.
|
149
|
-
def fsm_stat(type, property, percentile)
|
150
|
-
"node_#{type}_fsm_#{property}_#{percentile == 50 ? 'median' : percentile}"
|
151
|
-
end
|
152
|
-
|
153
|
-
# Returns the alerts state for the given fsm.
|
154
|
-
def fsm_state(type, percentile, val)
|
155
|
-
limit = opts["#{type}_#{percentile}_warning".to_sym]
|
156
|
-
case val
|
157
|
-
when 0..limit
|
158
|
-
'ok'
|
159
|
-
when limit..limit * 2
|
160
|
-
'warning'
|
161
|
-
else
|
162
|
-
'critical'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
# Get current stats via HTTP
|
167
|
-
def stats_http
|
168
|
-
begin
|
169
|
-
uri = URI.parse(opts[:riak_host])
|
170
|
-
uri.host = opts[:riak_host] if uri.host.nil?
|
171
|
-
http = Net::HTTP.new(uri.host, opts[:stats_port])
|
172
|
-
http.use_ssl = uri.scheme == 'https'
|
173
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
174
|
-
res = http.start do |h|
|
175
|
-
h.get opts[:stats_path]
|
176
|
-
end
|
177
|
-
rescue StandardError => e
|
178
|
-
report(
|
179
|
-
host: opts[:riak_host],
|
180
|
-
service: 'riak',
|
181
|
-
state: 'critical',
|
182
|
-
description: "error fetching #{opts[:riak_host]}:#{opts[:stats_port]} #{e.class}, #{e.message}",
|
183
|
-
)
|
184
|
-
raise
|
185
|
-
end
|
186
|
-
|
187
|
-
if res.code.to_i == 200
|
188
|
-
JSON.parse(res.body)
|
189
|
-
else
|
190
|
-
report(
|
191
|
-
host: opts[:riak_host],
|
192
|
-
service: 'riak',
|
193
|
-
state: 'critical',
|
194
|
-
description: "stats returned HTTP #{res.code}:\n\n#{res.body}",
|
195
|
-
)
|
196
|
-
raise "Can't fetch stats via HTTP: #{res.core}:\n\n#{res.body}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Get current stats via riak-admin
|
201
|
-
def stats_riak_admin
|
202
|
-
str = `riak-admin status`
|
203
|
-
raise 'riak-admin failed' unless $CHILD_STATUS == 0
|
204
|
-
|
205
|
-
Hash[str.split(/\n/).map { |i| i.split(/ : /) }]
|
206
|
-
end
|
207
|
-
|
208
|
-
# Get current stats as a hash
|
209
|
-
def stats
|
210
|
-
if @httpstatus
|
211
|
-
stats_http
|
212
|
-
elsif @riakadmin
|
213
|
-
stats_riak_admin
|
214
|
-
else
|
215
|
-
report(
|
216
|
-
host: opts[:riak_host],
|
217
|
-
service: 'riak',
|
218
|
-
state: 'critical',
|
219
|
-
description: 'No mechanism for fetching Riak stats: neither HTTP nor riak-admin available.',
|
220
|
-
)
|
221
|
-
raise 'No mechanism for fetching Riak stats: neither HTTP nor riak-admin available.'
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def core_services
|
226
|
-
%w[vnode_gets
|
227
|
-
vnode_puts
|
228
|
-
node_gets
|
229
|
-
node_puts
|
230
|
-
node_gets_set
|
231
|
-
node_puts_set
|
232
|
-
read_repairs]
|
233
|
-
end
|
234
|
-
|
235
|
-
def fsm_types
|
236
|
-
[{ 'get' => 'time' }, { 'put' => 'time' },
|
237
|
-
{ 'get' => 'set_objsize' },]
|
238
|
-
end
|
239
|
-
|
240
|
-
def fsm_percentiles
|
241
|
-
[50, 95, 99]
|
242
|
-
end
|
243
|
-
|
244
|
-
# Reports current stats to Riemann
|
245
|
-
def check_stats
|
246
|
-
begin
|
247
|
-
stats = self.stats
|
248
|
-
rescue StandardError => e
|
249
|
-
event = {
|
250
|
-
state: 'critical',
|
251
|
-
description: e.message,
|
252
|
-
host: opts[:riak_host],
|
253
|
-
}
|
254
|
-
# Report errors
|
255
|
-
report(event.merge(service: 'riak'))
|
256
|
-
core_services.each do |s|
|
257
|
-
report(event.merge(service: "riak #{s}"))
|
258
|
-
end
|
259
|
-
fsm_types.each do |typespec|
|
260
|
-
typespec.each do |type, prop|
|
261
|
-
fsm_percentiles.each do |percentile|
|
262
|
-
report(event.merge(service: "riak #{type} #{prop} #{percentile}"))
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
return
|
267
|
-
end
|
268
|
-
|
269
|
-
# Riak itself
|
270
|
-
report(
|
271
|
-
host: opts[:riak_host],
|
272
|
-
service: 'riak',
|
273
|
-
state: 'ok',
|
274
|
-
)
|
275
|
-
|
276
|
-
# Gets/puts/rr
|
277
|
-
core_services.each do |s|
|
278
|
-
report(
|
279
|
-
host: opts[:riak_host],
|
280
|
-
service: "riak #{s}",
|
281
|
-
state: 'ok',
|
282
|
-
metric: stats[s].to_i / 60.0,
|
283
|
-
description: "#{stats[s].to_i / 60.0}/sec",
|
284
|
-
)
|
285
|
-
end
|
286
|
-
|
287
|
-
# FSMs
|
288
|
-
fsm_types.each do |typespec|
|
289
|
-
typespec.each do |type, prop|
|
290
|
-
fsm_percentiles.each do |percentile|
|
291
|
-
val = stats[fsm_stat(type, prop, percentile)].to_i || 0
|
292
|
-
val = 0 if val == 'undefined'
|
293
|
-
val /= 1000.0 if prop == 'time' # Convert us to ms
|
294
|
-
state = if prop == 'time'
|
295
|
-
fsm_state(type, percentile, val)
|
296
|
-
else
|
297
|
-
'ok'
|
298
|
-
end
|
299
|
-
report(
|
300
|
-
host: opts[:riak_host],
|
301
|
-
service: "riak #{type} #{prop} #{percentile}",
|
302
|
-
state: state,
|
303
|
-
metric: val,
|
304
|
-
description: "#{val} ms",
|
305
|
-
)
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
def tick
|
312
|
-
# This can utterly destroy a cluster, so we disable
|
313
|
-
# check_keys
|
314
|
-
check_stats
|
315
|
-
check_ring
|
316
|
-
check_disk
|
317
|
-
check_transfers
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
6
|
+
require 'riemann/tools/riak'
|
322
7
|
|
323
8
|
Riemann::Tools::Riak.run
|