riemann-tools 1.1.0 → 1.3.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 +55 -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 +29 -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 +61 -7
- 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
data/lib/riemann/tools/health.rb
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'riemann/tools'
|
4
4
|
require 'riemann/tools/utils'
|
5
|
+
require 'riemann/tools/uptime_parser.tab'
|
5
6
|
|
7
|
+
# Reports current CPU, disk, load average, and memory use to riemann.
|
6
8
|
module Riemann
|
7
9
|
module Tools
|
8
10
|
class Health
|
@@ -14,12 +16,18 @@ module Riemann
|
|
14
16
|
opt :disk_warning, 'Disk warning threshold (fraction of space used)', default: 0.9
|
15
17
|
opt :disk_critical, 'Disk critical threshold (fraction of space used)', default: 0.95
|
16
18
|
opt :disk_ignorefs, 'A list of filesystem types to ignore',
|
17
|
-
default: %w[anon_inodefs autofs cd9660 devfs devtmpfs fdescfs iso9660 linprocfs linsysfs nfs procfs tmpfs]
|
19
|
+
default: %w[anon_inodefs autofs cd9660 devfs devtmpfs fdescfs iso9660 linprocfs linsysfs nfs overlay procfs squashfs tmpfs]
|
18
20
|
opt :load_warning, 'Load warning threshold (load average / core)', default: 3.0
|
19
21
|
opt :load_critical, 'Load critical threshold (load average / core)', default: 8.0
|
20
22
|
opt :memory_warning, 'Memory warning threshold (fraction of RAM)', default: 0.85
|
21
23
|
opt :memory_critical, 'Memory critical threshold (fraction of RAM)', default: 0.95
|
22
|
-
opt :
|
24
|
+
opt :uptime_warning, 'Uptime warning threshold', default: 86_400
|
25
|
+
opt :uptime_critical, 'Uptime critical threshold', default: 3600
|
26
|
+
opt :users_warning, 'Users warning threshold', default: 1
|
27
|
+
opt :users_critical, 'Users critical threshold', default: 1
|
28
|
+
opt :swap_warning, 'Swap warning threshold', default: 0.4
|
29
|
+
opt :swap_critical, 'Swap critical threshold', default: 0.5
|
30
|
+
opt :checks, 'A list of checks to run.', type: :strings, default: %w[cpu load memory disk swap]
|
23
31
|
|
24
32
|
def initialize
|
25
33
|
@limits = {
|
@@ -27,6 +35,9 @@ module Riemann
|
|
27
35
|
disk: { critical: opts[:disk_critical], warning: opts[:disk_warning] },
|
28
36
|
load: { critical: opts[:load_critical], warning: opts[:load_warning] },
|
29
37
|
memory: { critical: opts[:memory_critical], warning: opts[:memory_warning] },
|
38
|
+
uptime: { critical: opts[:uptime_critical], warning: opts[:uptime_warning] },
|
39
|
+
users: { critical: opts[:users_critical], warning: opts[:users_warning] },
|
40
|
+
swap: { critical: opts[:swap_critical], warning: opts[:swap_warning] },
|
30
41
|
}
|
31
42
|
case (@ostype = `uname -s`.chomp.downcase)
|
32
43
|
when 'darwin'
|
@@ -35,25 +46,32 @@ module Riemann
|
|
35
46
|
@disk = method :disk
|
36
47
|
@load = method :darwin_load
|
37
48
|
@memory = method :darwin_memory
|
38
|
-
|
49
|
+
@uptime = method :bsd_uptime
|
50
|
+
@swap = method :bsd_swap
|
39
51
|
when 'freebsd'
|
40
52
|
@cores = `sysctl -n hw.ncpu`.to_i
|
41
53
|
@cpu = method :freebsd_cpu
|
42
54
|
@disk = method :disk
|
43
55
|
@load = method :bsd_load
|
44
56
|
@memory = method :freebsd_memory
|
57
|
+
@uptime = method :bsd_uptime
|
58
|
+
@swap = method :bsd_swap
|
45
59
|
when 'openbsd'
|
46
60
|
@cores = `sysctl -n hw.ncpu`.to_i
|
47
61
|
@cpu = method :openbsd_cpu
|
48
62
|
@disk = method :disk
|
49
63
|
@load = method :bsd_load
|
50
64
|
@memory = method :openbsd_memory
|
65
|
+
@uptime = method :bsd_uptime
|
66
|
+
@swap = method :bsd_swap
|
51
67
|
when 'sunos'
|
52
68
|
@cores = `mpstat -a 2>/dev/null`.split[33].to_i
|
53
69
|
@cpu = method :sunos_cpu
|
54
70
|
@disk = method :disk
|
55
71
|
@load = method :bsd_load
|
56
72
|
@memory = method :sunos_memory
|
73
|
+
@uptime = method :bsd_uptime
|
74
|
+
@swap = method :bsd_swap
|
57
75
|
else
|
58
76
|
@cores = `nproc`.to_i
|
59
77
|
puts "WARNING: OS '#{@ostype}' not explicitly supported. Falling back to Linux" unless @ostype == 'linux'
|
@@ -61,8 +79,11 @@ module Riemann
|
|
61
79
|
@disk = method :disk
|
62
80
|
@load = method :linux_load
|
63
81
|
@memory = method :linux_memory
|
82
|
+
@uptime = method :linux_uptime
|
83
|
+
@swap = method :linux_swap
|
64
84
|
@supports_exclude_type = `df --help 2>&1 | grep -e "--exclude-type"` != ''
|
65
85
|
end
|
86
|
+
@users = method :users
|
66
87
|
|
67
88
|
opts[:checks].each do |check|
|
68
89
|
case check
|
@@ -74,6 +95,12 @@ module Riemann
|
|
74
95
|
@cpu_enabled = true
|
75
96
|
when 'memory'
|
76
97
|
@memory_enabled = true
|
98
|
+
when 'uptime'
|
99
|
+
@uptime_enabled = true
|
100
|
+
when 'users'
|
101
|
+
@users_enabled = true
|
102
|
+
when 'swap'
|
103
|
+
@swap_enabled = true
|
77
104
|
end
|
78
105
|
end
|
79
106
|
end
|
@@ -99,6 +126,30 @@ module Riemann
|
|
99
126
|
end
|
100
127
|
end
|
101
128
|
|
129
|
+
def report_int(service, value, report)
|
130
|
+
return unless value
|
131
|
+
|
132
|
+
if value >= @limits[service][:critical]
|
133
|
+
alert service, :critical, value, "#{value} #{report}"
|
134
|
+
elsif value >= @limits[service][:warning]
|
135
|
+
alert service, :warning, value, "#{value} #{report}"
|
136
|
+
else
|
137
|
+
alert service, :ok, value, "#{value} #{report}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def report_uptime(uptime)
|
142
|
+
description = uptime_to_human(uptime)
|
143
|
+
|
144
|
+
if uptime < @limits[:uptime][:critical]
|
145
|
+
alert 'uptime', :critical, uptime, description
|
146
|
+
elsif uptime < @limits[:uptime][:warning]
|
147
|
+
alert 'uptime', :warning, uptime, description
|
148
|
+
else
|
149
|
+
alert 'uptime', :ok, uptime, description
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
102
153
|
def linux_cpu
|
103
154
|
new = File.read('/proc/stat')
|
104
155
|
unless new[/cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/]
|
@@ -205,9 +256,16 @@ module Riemann
|
|
205
256
|
@old_cpu = [u2, s2, t2, i2]
|
206
257
|
end
|
207
258
|
|
259
|
+
def uptime_parser
|
260
|
+
@uptime_parser ||= UptimeParser.new
|
261
|
+
end
|
262
|
+
|
263
|
+
def uptime
|
264
|
+
@cached_data[:uptime] ||= uptime_parser.parse(`uptime`)
|
265
|
+
end
|
266
|
+
|
208
267
|
def bsd_load
|
209
|
-
|
210
|
-
load = m[0].to_f / @cores
|
268
|
+
load = uptime[:load_averages][1] / @cores
|
211
269
|
if load > @limits[:load][:critical]
|
212
270
|
alert 'load', :critical, load, "1-minute load average/core is #{load}"
|
213
271
|
elsif load > @limits[:load][:warning]
|
@@ -240,47 +298,50 @@ module Riemann
|
|
240
298
|
end
|
241
299
|
|
242
300
|
def darwin_top
|
301
|
+
return @cached_data[:darwin_top] if @cached_data[:darwin_top]
|
302
|
+
|
243
303
|
raw = `top -l 1 | grep -i "^\\(cpu\\|physmem\\|load\\)"`.chomp
|
244
|
-
|
304
|
+
topdata = {}
|
245
305
|
raw.each_line do |ln|
|
246
306
|
if ln.match(/Load Avg: [0-9.]+, [0-9.]+, ([0-9.])+/i)
|
247
|
-
|
307
|
+
topdata[:load] = Regexp.last_match(1).to_f
|
248
308
|
elsif ln.match(/CPU usage: [0-9.]+% user, [0-9.]+% sys, ([0-9.]+)% idle/i)
|
249
|
-
|
309
|
+
topdata[:cpu] = 1 - (Regexp.last_match(1).to_f / 100)
|
250
310
|
elsif (mdat = ln.match(/PhysMem: ([0-9]+)([BKMGT]) wired, ([0-9]+)([BKMGT]) active, ([0-9]+)([BKMGT]) inactive, ([0-9]+)([BKMGT]) used, ([0-9]+)([BKMGT]) free/i))
|
251
311
|
wired = mdat[1].to_i * (1024**'BKMGT'.index(mdat[2]))
|
252
312
|
active = mdat[3].to_i * (1024**'BKMGT'.index(mdat[4]))
|
253
313
|
inactive = mdat[5].to_i * (1024**'BKMGT'.index(mdat[6]))
|
254
314
|
used = mdat[7].to_i * (1024**'BKMGT'.index(mdat[8]))
|
255
315
|
free = mdat[9].to_i * (1024**'BKMGT'.index(mdat[10]))
|
256
|
-
|
316
|
+
topdata[:memory] = (wired + active + used).to_f / (wired + active + used + inactive + free)
|
257
317
|
# This is for OSX Mavericks which
|
258
318
|
# uses a different format for top
|
259
319
|
# Example: PhysMem: 4662M used (1328M wired), 2782M unused.
|
260
320
|
elsif (mdat = ln.match(/PhysMem: ([0-9]+)([BKMGT]) used \([0-9]+[BKMGT] wired\), ([0-9]+)([BKMGT]) unused/i))
|
261
321
|
used = mdat[1].to_i * (1024**'BKMGT'.index(mdat[2]))
|
262
322
|
unused = mdat[3].to_i * (1024**'BKMGT'.index(mdat[4]))
|
263
|
-
|
323
|
+
topdata[:memory] = used.to_f / (used + unused)
|
264
324
|
end
|
265
325
|
end
|
326
|
+
@cached_data[:darwin_top] = topdata
|
266
327
|
end
|
267
328
|
|
268
329
|
def darwin_cpu
|
269
|
-
|
270
|
-
unless
|
330
|
+
topdata = darwin_top
|
331
|
+
unless topdata[:cpu]
|
271
332
|
alert 'cpu', :unknown, nil, 'unable to get CPU stats from top'
|
272
333
|
return false
|
273
334
|
end
|
274
|
-
report_pct :cpu,
|
335
|
+
report_pct :cpu, topdata[:cpu], "usage\n\n#{reverse_numeric_sort_with_header(`ps -eo pcpu,pid,comm`)}"
|
275
336
|
end
|
276
337
|
|
277
338
|
def darwin_load
|
278
|
-
|
279
|
-
unless
|
339
|
+
topdata = darwin_top
|
340
|
+
unless topdata[:load]
|
280
341
|
alert 'load', :unknown, nil, 'unable to get load ave from top'
|
281
342
|
return false
|
282
343
|
end
|
283
|
-
metric =
|
344
|
+
metric = topdata[:load] / @cores
|
284
345
|
if metric > @limits[:load][:critical]
|
285
346
|
alert 'load', :critical, metric, "1-minute load average per core is #{metric}"
|
286
347
|
elsif metric > @limits[:load][:warning]
|
@@ -291,12 +352,12 @@ module Riemann
|
|
291
352
|
end
|
292
353
|
|
293
354
|
def darwin_memory
|
294
|
-
|
295
|
-
unless
|
355
|
+
topdata = darwin_top
|
356
|
+
unless topdata[:memory]
|
296
357
|
alert 'memory', :unknown, nil, 'unable to get memory data from top'
|
297
358
|
return false
|
298
359
|
end
|
299
|
-
report_pct :memory,
|
360
|
+
report_pct :memory, topdata[:memory], "usage\n\n#{reverse_numeric_sort_with_header(`ps -eo pmem,pid,comm`)}"
|
300
361
|
end
|
301
362
|
|
302
363
|
def df
|
@@ -336,11 +397,81 @@ module Riemann
|
|
336
397
|
end
|
337
398
|
end
|
338
399
|
|
400
|
+
def bsd_uptime
|
401
|
+
value = uptime[:uptime]
|
402
|
+
|
403
|
+
report_uptime(value)
|
404
|
+
end
|
405
|
+
|
406
|
+
def linux_uptime
|
407
|
+
value = File.read('/proc/uptime').split(/\s+/)[0].to_f
|
408
|
+
|
409
|
+
report_uptime(value)
|
410
|
+
end
|
411
|
+
|
412
|
+
def users
|
413
|
+
value = uptime[:users]
|
414
|
+
|
415
|
+
report_int(:users, value, "user#{'s' if value != 1}")
|
416
|
+
end
|
417
|
+
|
418
|
+
def bsd_swap
|
419
|
+
_device, blocks, used, _avail, _capacity = `swapinfo`.lines.last.split(/\s+/)
|
420
|
+
|
421
|
+
value = Float(used) / Integer(blocks)
|
422
|
+
|
423
|
+
report_pct :swap, value, 'used'
|
424
|
+
rescue ArgumentError
|
425
|
+
# Ignore
|
426
|
+
end
|
427
|
+
|
428
|
+
def linux_swap
|
429
|
+
total_size = 0.0
|
430
|
+
total_used = 0.0
|
431
|
+
|
432
|
+
File.read('/proc/swaps').lines.each_with_index do |line, n|
|
433
|
+
next if n.zero?
|
434
|
+
|
435
|
+
_filename, _type, size, used, _priority = line.split(/\s+/)
|
436
|
+
|
437
|
+
total_size += size.to_f
|
438
|
+
total_used += used.to_f
|
439
|
+
end
|
440
|
+
|
441
|
+
return if total_size.zero?
|
442
|
+
|
443
|
+
value = total_used / total_size
|
444
|
+
|
445
|
+
report_pct :swap, value, 'used'
|
446
|
+
end
|
447
|
+
|
448
|
+
def uptime_to_human(value)
|
449
|
+
seconds = value.to_i
|
450
|
+
days = seconds / 86_400
|
451
|
+
seconds %= 86_400
|
452
|
+
hrs = seconds / 3600
|
453
|
+
seconds %= 3600
|
454
|
+
mins = seconds / 60
|
455
|
+
[
|
456
|
+
("#{days} day#{'s' if days > 1}" unless days.zero?),
|
457
|
+
format('%<hrs>2d:%<mins>02d', hrs: hrs, mins: mins),
|
458
|
+
].compact.join(' ')
|
459
|
+
end
|
460
|
+
|
339
461
|
def tick
|
462
|
+
invalidate_cache
|
463
|
+
|
340
464
|
@cpu.call if @cpu_enabled
|
341
465
|
@memory.call if @memory_enabled
|
342
466
|
@disk.call if @disk_enabled
|
343
467
|
@load.call if @load_enabled
|
468
|
+
@uptime.call if @uptime_enabled
|
469
|
+
@users.call if @users_enabled
|
470
|
+
@swap.call if @swap_enabled
|
471
|
+
end
|
472
|
+
|
473
|
+
def invalidate_cache
|
474
|
+
@cached_data = {}
|
344
475
|
end
|
345
476
|
end
|
346
477
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Tools
|
7
|
+
class Kvm
|
8
|
+
include Riemann::Tools
|
9
|
+
|
10
|
+
def tick
|
11
|
+
# determine how many instances I have according to libvirt
|
12
|
+
kvm_instances = `LANG=C virsh list | grep -c running`
|
13
|
+
|
14
|
+
# submit them to riemann
|
15
|
+
report(
|
16
|
+
service: 'KVM Running VMs',
|
17
|
+
metric: kvm_instances.to_i,
|
18
|
+
state: 'info',
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
require 'riemann/tools/mdstat_parser.tab'
|
5
|
+
|
6
|
+
module Riemann
|
7
|
+
module Tools
|
8
|
+
class Md
|
9
|
+
include Riemann::Tools
|
10
|
+
|
11
|
+
def mdstat_parser
|
12
|
+
@mdstat_parser ||= MdstatParser.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def tick
|
16
|
+
status = File.read('/proc/mdstat')
|
17
|
+
res = mdstat_parser.parse(status)
|
18
|
+
|
19
|
+
state = res.values.all? { |value| value =~ /\AU+\z/ } ? 'ok' : 'critical'
|
20
|
+
|
21
|
+
report(
|
22
|
+
service: 'mdstat',
|
23
|
+
message: status,
|
24
|
+
state: state,
|
25
|
+
)
|
26
|
+
rescue Errno::ENOENT => e
|
27
|
+
report(
|
28
|
+
service: 'mdstat',
|
29
|
+
message: e.message,
|
30
|
+
state: 'critical',
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,340 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.6.0
|
4
|
+
# from Racc grammar file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
|
10
|
+
require 'strscan'
|
11
|
+
|
12
|
+
module Riemann
|
13
|
+
module Tools
|
14
|
+
class MdstatParser < Racc::Parser
|
15
|
+
|
16
|
+
module_eval(<<'...end mdstat_parser.y/module_eval...', 'mdstat_parser.y', 42)
|
17
|
+
|
18
|
+
def parse(text)
|
19
|
+
s = StringScanner.new(text)
|
20
|
+
@tokens = []
|
21
|
+
|
22
|
+
until s.eos? do
|
23
|
+
case
|
24
|
+
when s.scan(/\n/) then # ignore
|
25
|
+
when s.scan(/\s+/) then # ignore
|
26
|
+
|
27
|
+
when s.scan(/\[=*>.*\]/) then @tokens << [:PROGRESS, s.matched]
|
28
|
+
when s.scan(/%/) then @tokens << ['%', s.matched]
|
29
|
+
when s.scan(/,/) then @tokens << [',', s.matched]
|
30
|
+
when s.scan(/:/) then @tokens << [':', s.matched]
|
31
|
+
when s.scan(/</) then @tokens << ['<', s.matched]
|
32
|
+
when s.scan(/=/) then @tokens << ['=', s.matched]
|
33
|
+
when s.scan(/>/) then @tokens << ['>', s.matched]
|
34
|
+
when s.scan(/\(/) then @tokens << ['(', s.matched]
|
35
|
+
when s.scan(/\)/) then @tokens << [')', s.matched]
|
36
|
+
when s.scan(/\./) then @tokens << ['.', s.matched]
|
37
|
+
when s.scan(/\//) then @tokens << ['/', s.matched]
|
38
|
+
when s.scan(/\[/) then @tokens << ['[', s.matched]
|
39
|
+
when s.scan(/]/) then @tokens << [']', s.matched]
|
40
|
+
when s.scan(/algorithm/) then @tokens << [:ALGORITHM, s.matched]
|
41
|
+
when s.scan(/bitmap/) then @tokens << [:BITMAP, s.matched]
|
42
|
+
when s.scan(/blocks/) then @tokens << [:BLOCKS, s.matched]
|
43
|
+
when s.scan(/chunk/) then @tokens << [:CHUNK, s.matched]
|
44
|
+
when s.scan(/finish/) then @tokens << [:FINISH, s.matched]
|
45
|
+
when s.scan(/level/) then @tokens << [:LEVEL, s.matched]
|
46
|
+
when s.scan(/min/) then @tokens << [:MIN, s.matched]
|
47
|
+
when s.scan(/pages/) then @tokens << [:PAGES, s.matched]
|
48
|
+
when s.scan(/(raid([014-6]|10)|linear|multipath|faulty)\b/) then @tokens << [:PERSONALITY, s.matched]
|
49
|
+
when s.scan(/Personalities/) then @tokens << [:PERSONALITIES, s.matched]
|
50
|
+
when s.scan(/recovery/) then @tokens << [:RECOVERY, s.matched]
|
51
|
+
when s.scan(/speed/) then @tokens << [:SPEED, s.matched]
|
52
|
+
when s.scan(/super/) then @tokens << [:SUPER, s.matched]
|
53
|
+
when s.scan(/unused devices/) then @tokens << [:UNUSED_DEVICES, s.matched]
|
54
|
+
when s.scan(/K\/sec/) then @tokens << [:SPEED_UNIT, s.matched.to_i]
|
55
|
+
when s.scan(/KB/) then @tokens << [:BYTE_UNIT, s.matched.to_i]
|
56
|
+
when s.scan(/k/) then @tokens << [:UNIT, s.matched.to_i]
|
57
|
+
when s.scan(/\d+\.\d+/) then @tokens << [:FLOAT, s.matched.to_i]
|
58
|
+
when s.scan(/\d+/) then @tokens << [:INTEGER, s.matched.to_i]
|
59
|
+
when s.scan(/F\b/) then @tokens << [:FAILED, s.matched.to_i]
|
60
|
+
when s.scan(/\w+/) then @tokens << [:IDENTIFIER, s.matched]
|
61
|
+
else
|
62
|
+
raise s.rest
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
do_parse
|
67
|
+
end
|
68
|
+
|
69
|
+
def next_token
|
70
|
+
@tokens.shift
|
71
|
+
end
|
72
|
+
...end mdstat_parser.y/module_eval...
|
73
|
+
##### State transition tables begin ###
|
74
|
+
|
75
|
+
racc_action_table = [
|
76
|
+
10, 13, 14, 10, 29, 3, 4, 6, 7, 15,
|
77
|
+
16, 17, 18, 11, 19, 20, 21, 22, 23, 24,
|
78
|
+
10, 27, 28, 31, 32, 33, 35, 37, 38, 39,
|
79
|
+
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
|
80
|
+
50, 51, 52, 53, 54, 56, 58, 59, 60, 61,
|
81
|
+
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
|
82
|
+
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
|
83
|
+
82, 83, 84, 85, 86, 87, 88 ]
|
84
|
+
|
85
|
+
racc_action_check = [
|
86
|
+
5, 10, 10, 25, 25, 0, 1, 3, 4, 11,
|
87
|
+
12, 13, 14, 5, 15, 16, 17, 18, 19, 20,
|
88
|
+
21, 22, 23, 27, 29, 31, 32, 34, 35, 36,
|
89
|
+
37, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
90
|
+
48, 49, 50, 51, 52, 53, 55, 56, 58, 59,
|
91
|
+
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
|
92
|
+
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
93
|
+
80, 81, 82, 84, 85, 86, 87 ]
|
94
|
+
|
95
|
+
racc_action_pointer = [
|
96
|
+
-10, 6, nil, -17, 8, -10, nil, nil, nil, nil,
|
97
|
+
-23, -15, -15, 1, 1, -19, -1, 0, -9, 8,
|
98
|
+
-7, 10, -7, -12, nil, -7, nil, 16, nil, 20,
|
99
|
+
nil, -4, 5, nil, 15, 19, 4, 19, nil, 20,
|
100
|
+
2, 6, 23, 24, 14, 11, 32, 14, 10, 31,
|
101
|
+
40, 17, 33, 42, nil, 29, 23, nil, 30, 38,
|
102
|
+
19, 24, 43, 42, 22, 41, 28, 32, 47, 48,
|
103
|
+
33, 56, 51, 37, 35, 35, 58, 56, 37, 64,
|
104
|
+
61, 65, 59, nil, 54, 43, 64, 56, nil ]
|
105
|
+
|
106
|
+
racc_action_default = [
|
107
|
+
-21, -21, -6, -21, -21, -21, -4, 89, -1, -5,
|
108
|
+
-21, -21, -2, -21, -21, -21, -21, -21, -21, -21,
|
109
|
+
-21, -21, -11, -21, -3, -21, -9, -21, -20, -21,
|
110
|
+
-8, -21, -13, -10, -15, -21, -21, -21, -12, -21,
|
111
|
+
-21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
|
112
|
+
-21, -21, -21, -17, -14, -19, -21, -7, -21, -21,
|
113
|
+
-21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
|
114
|
+
-21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
|
115
|
+
-21, -21, -21, -16, -21, -21, -21, -21, -18 ]
|
116
|
+
|
117
|
+
racc_goto_table = [
|
118
|
+
9, 1, 2, 5, 8, 12, 25, 34, 36, 55,
|
119
|
+
57, nil, nil, nil, nil, nil, 26, nil, nil, nil,
|
120
|
+
30 ]
|
121
|
+
|
122
|
+
racc_goto_check = [
|
123
|
+
6, 1, 2, 3, 4, 5, 7, 8, 9, 10,
|
124
|
+
11, nil, nil, nil, nil, nil, 6, nil, nil, nil,
|
125
|
+
6 ]
|
126
|
+
|
127
|
+
racc_goto_pointer = [
|
128
|
+
nil, 1, 2, 1, -1, -1, -5, -15, -25, -26,
|
129
|
+
-44, -45 ]
|
130
|
+
|
131
|
+
racc_goto_default = [
|
132
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
133
|
+
nil, nil ]
|
134
|
+
|
135
|
+
racc_reduce_table = [
|
136
|
+
0, 0, :racc_error,
|
137
|
+
3, 36, :_reduce_1,
|
138
|
+
3, 37, :_reduce_none,
|
139
|
+
4, 40, :_reduce_none,
|
140
|
+
0, 40, :_reduce_none,
|
141
|
+
2, 38, :_reduce_5,
|
142
|
+
0, 38, :_reduce_6,
|
143
|
+
19, 41, :_reduce_7,
|
144
|
+
2, 42, :_reduce_none,
|
145
|
+
1, 42, :_reduce_none,
|
146
|
+
7, 41, :_reduce_none,
|
147
|
+
4, 41, :_reduce_none,
|
148
|
+
2, 43, :_reduce_none,
|
149
|
+
0, 43, :_reduce_none,
|
150
|
+
9, 44, :_reduce_none,
|
151
|
+
0, 44, :_reduce_none,
|
152
|
+
14, 45, :_reduce_none,
|
153
|
+
0, 45, :_reduce_none,
|
154
|
+
18, 46, :_reduce_none,
|
155
|
+
0, 46, :_reduce_none,
|
156
|
+
5, 39, :_reduce_none ]
|
157
|
+
|
158
|
+
racc_reduce_n = 21
|
159
|
+
|
160
|
+
racc_shift_n = 89
|
161
|
+
|
162
|
+
racc_token_table = {
|
163
|
+
false => 0,
|
164
|
+
:error => 1,
|
165
|
+
:ALGORITHM => 2,
|
166
|
+
:BITMAP => 3,
|
167
|
+
:BLOCKS => 4,
|
168
|
+
:BYTE_UNIT => 5,
|
169
|
+
:CHUNK => 6,
|
170
|
+
:FAILED => 7,
|
171
|
+
:FINISH => 8,
|
172
|
+
:FLOAT => 9,
|
173
|
+
:IDENTIFIER => 10,
|
174
|
+
:INTEGER => 11,
|
175
|
+
:LEVEL => 12,
|
176
|
+
:MIN => 13,
|
177
|
+
:PAGES => 14,
|
178
|
+
:PERSONALITIES => 15,
|
179
|
+
:PERSONALITY => 16,
|
180
|
+
:PROGRESS => 17,
|
181
|
+
:RECOVERY => 18,
|
182
|
+
:SPEED => 19,
|
183
|
+
:SPEED_UNIT => 20,
|
184
|
+
:SUPER => 21,
|
185
|
+
:UNIT => 22,
|
186
|
+
:UNUSED_DEVICES => 23,
|
187
|
+
":" => 24,
|
188
|
+
"[" => 25,
|
189
|
+
"]" => 26,
|
190
|
+
"/" => 27,
|
191
|
+
"(" => 28,
|
192
|
+
")" => 29,
|
193
|
+
"," => 30,
|
194
|
+
"=" => 31,
|
195
|
+
"%" => 32,
|
196
|
+
"<" => 33,
|
197
|
+
">" => 34 }
|
198
|
+
|
199
|
+
racc_nt_base = 35
|
200
|
+
|
201
|
+
racc_use_result_var = true
|
202
|
+
|
203
|
+
Racc_arg = [
|
204
|
+
racc_action_table,
|
205
|
+
racc_action_check,
|
206
|
+
racc_action_default,
|
207
|
+
racc_action_pointer,
|
208
|
+
racc_goto_table,
|
209
|
+
racc_goto_check,
|
210
|
+
racc_goto_default,
|
211
|
+
racc_goto_pointer,
|
212
|
+
racc_nt_base,
|
213
|
+
racc_reduce_table,
|
214
|
+
racc_token_table,
|
215
|
+
racc_shift_n,
|
216
|
+
racc_reduce_n,
|
217
|
+
racc_use_result_var ]
|
218
|
+
|
219
|
+
Racc_token_to_s_table = [
|
220
|
+
"$end",
|
221
|
+
"error",
|
222
|
+
"ALGORITHM",
|
223
|
+
"BITMAP",
|
224
|
+
"BLOCKS",
|
225
|
+
"BYTE_UNIT",
|
226
|
+
"CHUNK",
|
227
|
+
"FAILED",
|
228
|
+
"FINISH",
|
229
|
+
"FLOAT",
|
230
|
+
"IDENTIFIER",
|
231
|
+
"INTEGER",
|
232
|
+
"LEVEL",
|
233
|
+
"MIN",
|
234
|
+
"PAGES",
|
235
|
+
"PERSONALITIES",
|
236
|
+
"PERSONALITY",
|
237
|
+
"PROGRESS",
|
238
|
+
"RECOVERY",
|
239
|
+
"SPEED",
|
240
|
+
"SPEED_UNIT",
|
241
|
+
"SUPER",
|
242
|
+
"UNIT",
|
243
|
+
"UNUSED_DEVICES",
|
244
|
+
"\":\"",
|
245
|
+
"\"[\"",
|
246
|
+
"\"]\"",
|
247
|
+
"\"/\"",
|
248
|
+
"\"(\"",
|
249
|
+
"\")\"",
|
250
|
+
"\",\"",
|
251
|
+
"\"=\"",
|
252
|
+
"\"%\"",
|
253
|
+
"\"<\"",
|
254
|
+
"\">\"",
|
255
|
+
"$start",
|
256
|
+
"target",
|
257
|
+
"personalities",
|
258
|
+
"devices",
|
259
|
+
"unused_devices",
|
260
|
+
"list_of_personalities",
|
261
|
+
"device",
|
262
|
+
"list_of_devices",
|
263
|
+
"super",
|
264
|
+
"level",
|
265
|
+
"bitmap",
|
266
|
+
"restore_progress" ]
|
267
|
+
|
268
|
+
Racc_debug_parser = false
|
269
|
+
|
270
|
+
##### State transition tables end #####
|
271
|
+
|
272
|
+
# reduce 0 omitted
|
273
|
+
|
274
|
+
module_eval(<<'.,.,', 'mdstat_parser.y', 3)
|
275
|
+
def _reduce_1(val, _values, result)
|
276
|
+
result = val[1]
|
277
|
+
result
|
278
|
+
end
|
279
|
+
.,.,
|
280
|
+
|
281
|
+
# reduce 2 omitted
|
282
|
+
|
283
|
+
# reduce 3 omitted
|
284
|
+
|
285
|
+
# reduce 4 omitted
|
286
|
+
|
287
|
+
module_eval(<<'.,.,', 'mdstat_parser.y', 10)
|
288
|
+
def _reduce_5(val, _values, result)
|
289
|
+
result = val[0].merge(val[1])
|
290
|
+
result
|
291
|
+
end
|
292
|
+
.,.,
|
293
|
+
|
294
|
+
module_eval(<<'.,.,', 'mdstat_parser.y', 11)
|
295
|
+
def _reduce_6(val, _values, result)
|
296
|
+
result = {}
|
297
|
+
result
|
298
|
+
end
|
299
|
+
.,.,
|
300
|
+
|
301
|
+
module_eval(<<'.,.,', 'mdstat_parser.y', 13)
|
302
|
+
def _reduce_7(val, _values, result)
|
303
|
+
result = { val[0] => val[15] }
|
304
|
+
result
|
305
|
+
end
|
306
|
+
.,.,
|
307
|
+
|
308
|
+
# reduce 8 omitted
|
309
|
+
|
310
|
+
# reduce 9 omitted
|
311
|
+
|
312
|
+
# reduce 10 omitted
|
313
|
+
|
314
|
+
# reduce 11 omitted
|
315
|
+
|
316
|
+
# reduce 12 omitted
|
317
|
+
|
318
|
+
# reduce 13 omitted
|
319
|
+
|
320
|
+
# reduce 14 omitted
|
321
|
+
|
322
|
+
# reduce 15 omitted
|
323
|
+
|
324
|
+
# reduce 16 omitted
|
325
|
+
|
326
|
+
# reduce 17 omitted
|
327
|
+
|
328
|
+
# reduce 18 omitted
|
329
|
+
|
330
|
+
# reduce 19 omitted
|
331
|
+
|
332
|
+
# reduce 20 omitted
|
333
|
+
|
334
|
+
def _reduce_none(val, _values, result)
|
335
|
+
val[0]
|
336
|
+
end
|
337
|
+
|
338
|
+
end # class MdstatParser
|
339
|
+
end # module Tools
|
340
|
+
end # module Riemann
|