riemann-babbler 1.4.0 → 2.0.0pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/Gemfile +2 -16
- data/Gemfile.lock +25 -39
- data/LICENSE.txt +22 -0
- data/README.md +18 -16
- data/bin/riemann-babbler +30 -10
- data/lib/riemann/babbler/errors.rb +13 -0
- data/lib/riemann/babbler/logging.rb +36 -0
- data/lib/riemann/babbler/{support/deep_merge.rb → monkey_patches.rb} +25 -16
- data/lib/riemann/babbler/options.rb +43 -0
- data/lib/riemann/babbler/plugin.rb +154 -0
- data/lib/riemann/babbler/plugin_loader.rb +86 -0
- data/lib/riemann/babbler/plugins/cpu.rb +14 -11
- data/lib/riemann/babbler/plugins/cpu_fan.rb +2 -2
- data/lib/riemann/babbler/plugins/cpu_temp.rb +2 -2
- data/lib/riemann/babbler/plugins/disk.rb +12 -6
- data/lib/riemann/babbler/plugins/{diskstat.rb → disk_stat.rb} +18 -18
- data/lib/riemann/babbler/plugins/errors_reporter.rb +34 -0
- data/lib/riemann/babbler/plugins/exim4.rb +2 -2
- data/lib/riemann/babbler/plugins/find_files.rb +7 -7
- data/lib/riemann/babbler/plugins/haproxy.rb +7 -7
- data/lib/riemann/babbler/plugins/helpers/init.rb +2 -0
- data/lib/riemann/babbler/plugins/helpers/rest.rb +28 -0
- data/lib/riemann/babbler/plugins/helpers/shell.rb +37 -0
- data/lib/riemann/babbler/plugins/http.rb +4 -6
- data/lib/riemann/babbler/plugins/la.rb +11 -3
- data/lib/riemann/babbler/plugins/mdadm.rb +10 -10
- data/lib/riemann/babbler/plugins/mega_cli.rb +2 -2
- data/lib/riemann/babbler/plugins/memory.rb +21 -17
- data/lib/riemann/babbler/plugins/net.rb +7 -5
- data/lib/riemann/babbler/plugins/net_stat.rb +5 -5
- data/lib/riemann/babbler/plugins/nginx.rb +2 -2
- data/lib/riemann/babbler/plugins/pgsql.rb +13 -13
- data/lib/riemann/babbler/plugins/runit.rb +6 -7
- data/lib/riemann/babbler/plugins/status_file.rb +4 -4
- data/lib/riemann/babbler/plugins/tw_cli.rb +5 -5
- data/lib/riemann/babbler/responder.rb +45 -0
- data/lib/riemann/babbler/sender.rb +102 -0
- data/lib/riemann/babbler/version.rb +2 -2
- data/lib/riemann/babbler.rb +8 -175
- data/riemann-babbler.gemspec +30 -26
- metadata +39 -38
- data/config.yml +0 -72
- data/lib/riemann/babbler/plugins/dummy.rb +0 -12
- data/lib/riemann/babbler/start.rb +0 -159
- data/lib/riemann/babbler/support/errors.rb +0 -3
- data/lib/riemann/babbler/support/monkey_patches.rb +0 -42
- data/lib/riemann/babbler/support/plugin_helpers.rb +0 -104
- data/lib/riemann/babbler/support/responder.rb +0 -29
- data/spec/config.yml +0 -15
- data/spec/default.rb +0 -61
@@ -1,18 +1,17 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
-
class Riemann::Babbler::Cpu < Riemann::Babbler
|
4
|
-
|
5
|
-
def desc
|
6
|
-
"#{shell('ps -eo pcpu,pid,cmd --sort -pcpu | head -3').chomp}"
|
7
|
-
end
|
3
|
+
class Riemann::Babbler::Plugin::Cpu < Riemann::Babbler::Plugin
|
8
4
|
|
9
5
|
def init
|
10
6
|
@old_cpu = Hash.new
|
7
|
+
plugin.set_default(:service, 'cpu usage')
|
8
|
+
plugin.set_default(:per_processor, false)
|
9
|
+
plugin.states.set_default(:warning, 70)
|
10
|
+
plugin.states.set_default(:critical, 85)
|
11
11
|
end
|
12
12
|
|
13
13
|
def collect
|
14
14
|
array = Array.new
|
15
|
-
description = desc
|
16
15
|
File.read('/proc/stat').split("\n").each do |cpu_line|
|
17
16
|
|
18
17
|
# проверяем есть строчка /cpu\d+/ или /cpu / и сграбливаем это в переменную
|
@@ -26,17 +25,21 @@ class Riemann::Babbler::Cpu < Riemann::Babbler
|
|
26
25
|
|
27
26
|
unless @old_cpu[cpu_number].nil?
|
28
27
|
u1, n1, s1, i1 = @old_cpu[cpu_number]
|
29
|
-
used
|
30
|
-
total
|
31
|
-
fraction
|
28
|
+
used = (u2+n2+s2) - (u1+n1+s1)
|
29
|
+
total = used + i2-i1
|
30
|
+
fraction = used.to_f / total
|
32
31
|
end
|
33
32
|
|
34
33
|
@old_cpu[cpu_number] = [u2, n2, s2, i2]
|
35
34
|
# _total идет с трешхолдом, а все остальное без трешхолда
|
36
35
|
if cpu_number == '_total'
|
37
|
-
array << {
|
36
|
+
array << {
|
37
|
+
:service => plugin.service + " cpu#{cpu_number}", :metric => fraction, :description => "Cpu#{cpu_number} usage\n"
|
38
|
+
} if fraction
|
38
39
|
else
|
39
|
-
array << {
|
40
|
+
array << {
|
41
|
+
:service => plugin.service + " cpu#{cpu_number}", :metric => fraction, :description => "Cpu#{cpu_number} usage\n", :state => 'ok'
|
42
|
+
} if fraction && plugin.per_processor
|
40
43
|
end
|
41
44
|
end
|
42
45
|
array
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::CpuFan < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::CpuFan < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'cpufan')
|
@@ -13,7 +13,7 @@ class Riemann::Babbler::CpuFan < Riemann::Babbler
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def collect
|
16
|
-
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'CPU Fan Speed'}
|
16
|
+
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'CPU Fan Speed' }
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::CpuTemp < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::CpuTemp < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'cputemp')
|
@@ -13,7 +13,7 @@ class Riemann::Babbler::CpuTemp < Riemann::Babbler
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def collect
|
16
|
-
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'CPU Temperature'}
|
16
|
+
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'CPU Temperature' }
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -1,32 +1,38 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
-
class Riemann::Babbler::Disk < Riemann::Babbler
|
3
|
+
class Riemann::Babbler::Plugin::Disk < Riemann::Babbler::Plugin
|
4
4
|
|
5
5
|
require 'sys/filesystem'
|
6
6
|
include Sys
|
7
7
|
|
8
8
|
NOT_MONITORING_FS = %w(sysfs nfs devpts squashfs proc devtmpfs)
|
9
9
|
|
10
|
+
def init
|
11
|
+
plugin.set_default(:service, 'disk')
|
12
|
+
plugin.states.set_default(:warning, 70)
|
13
|
+
plugin.states.set_default(:critical, 85)
|
14
|
+
end
|
15
|
+
|
10
16
|
def collect
|
11
17
|
# собираем только необходимые для мониторинга маунт-поинты
|
12
18
|
# точнее выбираем из mounts только те, у которых fstype не попадает
|
13
19
|
# в NOT_MONITORING_FS
|
14
|
-
monit_points = []
|
20
|
+
monit_points = []
|
15
21
|
File.open('/proc/mounts', 'r') do |file|
|
16
22
|
while (line = file.gets)
|
17
23
|
mtab = line.split(/\s+/)
|
18
|
-
monit_points << mtab[1] unless NOT_MONITORING_FS.include? mtab[2]
|
24
|
+
monit_points << mtab[1] unless NOT_MONITORING_FS.include? mtab[2]
|
19
25
|
end
|
20
26
|
end
|
21
27
|
disk = Array.new
|
22
28
|
monit_points.each do |point|
|
23
|
-
point_stat
|
29
|
+
point_stat = Filesystem.stat point
|
24
30
|
human_point = point == '/' ? '/root' : point
|
25
31
|
human_point = human_point.gsub(/^\//, '').gsub(/\//, '_')
|
26
32
|
disk << { :service => plugin.service + " #{human_point} % block", :description => "Disk usage #{point}, %", :metric => (1- point_stat.blocks_available.to_f/point_stat.blocks).round(2) * 100 } unless point_stat.blocks == 0
|
27
33
|
disk << { :service => plugin.service + " #{human_point} % inode", :description => "Disk usage #{point}, inodes %", :metric => (1 - point_stat.files_available.to_f/point_stat.files).round(2) * 100 } unless point_stat.files == 0
|
28
|
-
disk << { :service => plugin.service + " #{human_point} abs free", :description => "Disk free #{point}, B", :metric =>
|
29
|
-
disk << { :service => plugin.service + " #{human_point} abs total", :description => "Disk space #{point}, B",
|
34
|
+
disk << { :service => plugin.service + " #{human_point} abs free", :description => "Disk free #{point}, B", :metric => point_stat.blocks_free * point_stat.block_size, :state => 'ok' }
|
35
|
+
disk << { :service => plugin.service + " #{human_point} abs total", :description => "Disk space #{point}, B", :metric => point_stat.blocks * point_stat.block_size, :state => 'ok' }
|
30
36
|
end
|
31
37
|
disk
|
32
38
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
class Riemann::Babbler::
|
1
|
+
class Riemann::Babbler::Plugin::DiskStat < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
WORDS = [
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
'reads reqs',
|
5
|
+
'reads merged',
|
6
|
+
'reads sector',
|
7
|
+
'reads time',
|
8
|
+
'writes reqs',
|
9
|
+
'writes merged',
|
10
|
+
'writes sector',
|
11
|
+
'writes time',
|
12
|
+
'io reqs',
|
13
|
+
'io time',
|
14
|
+
'io weighted'
|
15
15
|
]
|
16
16
|
|
17
17
|
def init
|
@@ -26,22 +26,22 @@ class Riemann::Babbler::Diskstat < Riemann::Babbler
|
|
26
26
|
|
27
27
|
def collect
|
28
28
|
status = Array.new
|
29
|
-
f
|
30
|
-
f.split("\n").reject { |d| d =~ /(ram|loop)/ }.inject({}) do |
|
29
|
+
f = File.read('/proc/diskstats')
|
30
|
+
f.split("\n").reject { |d| d =~ /(ram|loop)/ }.inject({}) do |_, line|
|
31
31
|
if line =~ /^(?:\s+\d+){2}\s+([\w\d]+) (.*)$/
|
32
|
-
dev
|
32
|
+
dev = $1
|
33
33
|
values = $2.split(/\s+/).map { |str| str.to_i }
|
34
34
|
# пропускаем неинтересные девайсы
|
35
35
|
# которые закнчиваются на число, но при этом не пропускаем xvd
|
36
36
|
next if !!(dev.match /\d+$/ || !(dev.match =~ /^xvd/))
|
37
37
|
# читаем все фильтры
|
38
38
|
plugin.filter.each do |filter|
|
39
|
-
status << { :service => "#{plugin.service} #{dev} #{filter}", :metric => values[WORDS.index(filter)], :as_diff => true}
|
39
|
+
status << { :service => "#{plugin.service} #{dev} #{filter}", :metric => values[WORDS.index(filter)], :as_diff => true }
|
40
40
|
end
|
41
41
|
# добавляем iops
|
42
42
|
iops = values[WORDS.index('reads reqs')].to_i + values[WORDS.index('writes reqs')].to_i
|
43
|
-
status << { :service => "#{plugin.service} #{dev} iops", :metric => iops, :as_diff => true}
|
44
|
-
end
|
43
|
+
status << { :service => "#{plugin.service} #{dev} iops", :metric => iops, :as_diff => true }
|
44
|
+
end
|
45
45
|
end
|
46
46
|
status
|
47
47
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Riemann::Babbler::Plugin::ErrorsReporter < Riemann::Babbler::Plugin
|
2
|
+
|
3
|
+
def init
|
4
|
+
plugin.set_default(:service, 'riemann client')
|
5
|
+
@report_ok = false
|
6
|
+
end
|
7
|
+
|
8
|
+
def collect
|
9
|
+
status = Array.new
|
10
|
+
messages = Array.new
|
11
|
+
|
12
|
+
opts.errors.to_hash.each do |plugin_name, plugin_status|
|
13
|
+
next if plugin_status[:reported]
|
14
|
+
messages << "#{plugin_name} count_errors: #{plugin_status[:count]}, \
|
15
|
+
last: #{plugin_status[:last_error_at]}"
|
16
|
+
opts.errors.send(plugin_name).reported = true
|
17
|
+
end
|
18
|
+
|
19
|
+
if messages.empty?
|
20
|
+
status << { :service => plugin.service, :state => 'ok', :description => "All plugins ok" } unless @report_ok
|
21
|
+
@report_ok = true
|
22
|
+
else
|
23
|
+
@report_ok = false
|
24
|
+
status << {
|
25
|
+
:service => plugin.service,
|
26
|
+
:state => 'critical',
|
27
|
+
:metric => messages.count,
|
28
|
+
:description => "Problem with plugins:\n #{messages.join("\n")}"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
status
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::Exim4 < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::Exim4 < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'exim4')
|
@@ -13,7 +13,7 @@ class Riemann::Babbler::Exim4 < Riemann::Babbler
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def collect
|
16
|
-
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'Exim4: count frozen mails'}
|
16
|
+
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'Exim4: count frozen mails' }
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'find'
|
2
2
|
|
3
|
-
class Riemann::Babbler::
|
3
|
+
class Riemann::Babbler::Plugin::FindFiles < Riemann::Babbler::Plugin
|
4
4
|
|
5
5
|
def init
|
6
6
|
plugin.set_default(:service, 'find files')
|
7
7
|
plugin.set_default(:interval, 60)
|
8
|
-
plugin.set_default(:file_mask, '.*')
|
8
|
+
plugin.set_default(:file_mask, '.*') # file search mask
|
9
9
|
plugin.set_default(:dir, '/tmp/directory') # search in dir
|
10
|
-
plugin.set_default(:age, 1440)
|
10
|
+
plugin.set_default(:age, 1440) # in minute
|
11
11
|
plugin.states.set_default(:warning, 5)
|
12
12
|
end
|
13
13
|
|
14
14
|
def collect
|
15
15
|
return [] unless File.directory?(plugin.dir)
|
16
|
-
|
17
|
-
file_mask
|
16
|
+
count_files = 0
|
17
|
+
file_mask = Regexp.new(plugin.file_mask)
|
18
18
|
Find.find(plugin.dir).each do |file|
|
19
19
|
next unless File.file? file
|
20
20
|
next unless file_mask.match file
|
21
21
|
next unless Time.now.to_i - (plugin.age * 60) > File.new(file).mtime.to_i
|
22
|
-
|
22
|
+
count_files += 1
|
23
23
|
end
|
24
|
-
{ :service => plugin.service, :metric =>
|
24
|
+
{ :service => plugin.service, :metric => count_files, :description => "Count files in #{plugin.dir}" }
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'csv'
|
3
3
|
|
4
|
-
class Riemann::Babbler::Haproxy < Riemann::Babbler
|
5
|
-
|
4
|
+
class Riemann::Babbler::Plugin::Haproxy < Riemann::Babbler::Plugin
|
5
|
+
|
6
6
|
def init
|
7
7
|
plugin.set_default(:service, 'haproxy')
|
8
8
|
plugin.set_default(:interval, 60)
|
@@ -10,18 +10,18 @@ class Riemann::Babbler::Haproxy < Riemann::Babbler
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def collect
|
13
|
-
status
|
13
|
+
status = Array.new
|
14
14
|
content = rest_get(plugin.url)
|
15
|
-
csv
|
15
|
+
csv = CSV.parse(content.split('# ')[1], { :headers => true })
|
16
16
|
csv.each do |row|
|
17
17
|
row = row.to_hash
|
18
18
|
ns = "haproxy #{row['pxname']} #{row['svname']}"
|
19
19
|
row.each do |property, metric|
|
20
20
|
unless (property.nil? || property == 'pxname' || property == 'svname')
|
21
21
|
status << {
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
:service => "#{ns} #{property}",
|
23
|
+
:metric => metric.to_f,
|
24
|
+
:state => (%w(UP OPEN).include?(row['status']) ? 'ok' : 'critical')
|
25
25
|
}
|
26
26
|
end
|
27
27
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Babbler
|
7
|
+
module Plugins
|
8
|
+
module Helpers
|
9
|
+
|
10
|
+
# http rest
|
11
|
+
def rest_get(url)
|
12
|
+
begin
|
13
|
+
Timeout::timeout(plugin.timeout) do
|
14
|
+
begin
|
15
|
+
RestClient.get url
|
16
|
+
rescue
|
17
|
+
raise "Get from url: #{url} failed"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
rescue Timeout::Error
|
21
|
+
raise "Get from url: #{url}, timeout error"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module Riemann
|
6
|
+
module Babbler
|
7
|
+
module Plugins
|
8
|
+
module Helpers
|
9
|
+
|
10
|
+
# helper: stdout+stderr и exit status
|
11
|
+
def shell(*cmd)
|
12
|
+
exit_status=nil
|
13
|
+
err =nil
|
14
|
+
out =nil
|
15
|
+
Timeout::timeout(plugin.timeout) {
|
16
|
+
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
|
17
|
+
err = stderr.gets(nil)
|
18
|
+
out = stdout.gets(nil)
|
19
|
+
[stdin, stdout, stderr].each { |stream| stream.send('close') }
|
20
|
+
exit_status = wait_thread.value
|
21
|
+
end
|
22
|
+
}
|
23
|
+
if exit_status.to_i > 0
|
24
|
+
err = err.chomp if err
|
25
|
+
raise 'Error while running shell: ' + err.to_s
|
26
|
+
elsif out
|
27
|
+
return out.strip
|
28
|
+
else
|
29
|
+
# exit status 0, no stdout
|
30
|
+
''
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
class Riemann::Babbler::Http < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::Http < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'http check')
|
5
5
|
plugin.set_default(:interval, 60)
|
6
|
-
|
7
6
|
plugin.states.set_default(:critical, 1)
|
8
|
-
|
9
7
|
plugin.set_default(:http_code, 200)
|
10
8
|
plugin.set_default(:http_method, 'GET')
|
11
9
|
plugin.set_default(:connect_timeout, 5)
|
@@ -13,14 +11,14 @@ class Riemann::Babbler::Http < Riemann::Babbler
|
|
13
11
|
plugin.set_default(:retry_delay, 0)
|
14
12
|
plugin.set_default(:max_time, 10)
|
15
13
|
plugin.set_default(:insecure, false)
|
16
|
-
|
14
|
+
|
17
15
|
plugin.set_default(:url, 'http://127.0.0.1:80')
|
18
16
|
end
|
19
17
|
|
20
18
|
def collect
|
21
19
|
command = "curl -X#{plugin.http_method} -s"
|
22
20
|
command += " --connect-timeout #{plugin.connect_timeout}"
|
23
|
-
command +=
|
21
|
+
command += ' --insecure ' if plugin.insecure
|
24
22
|
command += " -w '%{http_code}\\n'"
|
25
23
|
command += " --retry #{plugin.retry} --retry-delay #{plugin.retry_delay}"
|
26
24
|
command += " --max-time #{plugin.max_time} --fail"
|
@@ -34,6 +32,6 @@ class Riemann::Babbler::Http < Riemann::Babbler
|
|
34
32
|
metric = 0
|
35
33
|
end
|
36
34
|
|
37
|
-
{:service => plugin.service, :metric => metric, :description => "http_code: #{out}"}
|
35
|
+
{ :service => plugin.service, :metric => metric, :description => "http_code: #{out}" }
|
38
36
|
end
|
39
37
|
end
|
@@ -1,9 +1,17 @@
|
|
1
|
-
|
1
|
+
class Riemann::Babbler::Plugin::La < Riemann::Babbler::Plugin
|
2
2
|
|
3
|
-
|
3
|
+
def init
|
4
|
+
plugin.set_default(:service, 'la')
|
5
|
+
plugin.states.set_default(:warning, 4)
|
6
|
+
plugin.states.set_default(:critical, 10)
|
7
|
+
end
|
4
8
|
|
5
9
|
def collect
|
6
|
-
{
|
10
|
+
{
|
11
|
+
:service => plugin.service + ' la_1',
|
12
|
+
:description => 'LA averaged over 1 minute',
|
13
|
+
:metric => File.read('/proc/loadavg').scan(/[\d\.]+/).first.to_f
|
14
|
+
}
|
7
15
|
end
|
8
16
|
|
9
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::Mdadm < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::Mdadm < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'mdadm')
|
@@ -11,23 +11,23 @@ class Riemann::Babbler::Mdadm < Riemann::Babbler
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def rm_bracket(text)
|
14
|
-
text.gsub('[','').gsub(']','')
|
14
|
+
text.gsub('[', '').gsub(']', '')
|
15
15
|
end
|
16
16
|
|
17
17
|
def mdadm_status_well?(text)
|
18
|
-
text.gsub(/U/,'').empty?
|
18
|
+
text.gsub(/U/, '').empty?
|
19
19
|
end
|
20
20
|
|
21
|
-
def collect
|
22
|
-
file
|
21
|
+
def collect
|
22
|
+
file = File.read('/proc/mdstat').split("\n")
|
23
23
|
status = Array.new
|
24
24
|
file.each_with_index do |line, index|
|
25
25
|
next unless line.include?('blocks')
|
26
26
|
|
27
27
|
device = file[index-1].split(':')[0].strip
|
28
28
|
|
29
|
-
mdstatus = rm_bracket(line.split(
|
30
|
-
next if mdadm_status_well?(mdstatus)
|
29
|
+
mdstatus = rm_bracket(line.split(' ').last) # UUU
|
30
|
+
next if mdadm_status_well?(mdstatus) # пропускаем все збс
|
31
31
|
if mdstatus == plugin.states.send(device).to_s # пропускаем если стейт зафикисирован в конфиге
|
32
32
|
status << { :service => plugin.service + " #{device}", :metric => 1, :state => 'ok', :description => "mdadm failed device #{device}, but disabled in config" }
|
33
33
|
next
|
@@ -43,11 +43,11 @@ class Riemann::Babbler::Mdadm < Riemann::Babbler
|
|
43
43
|
failed_parts = []
|
44
44
|
Dir["/sys/block/#{device}/md/dev-*"].each do |p|
|
45
45
|
state = File.read("#{p}/state").strip
|
46
|
-
next unless state !=
|
47
|
-
p.gsub!(/.+\/dev-/,
|
46
|
+
next unless state != 'in_sync'
|
47
|
+
p.gsub!(/.+\/dev-/, '')
|
48
48
|
failed_parts << "#{p} (#{state})"
|
49
49
|
end
|
50
|
-
failed_parts.join(
|
50
|
+
failed_parts.join(', ')
|
51
51
|
rescue
|
52
52
|
nil
|
53
53
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::MegaCli < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::MegaCli < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'megacli')
|
@@ -12,7 +12,7 @@ class Riemann::Babbler::MegaCli < Riemann::Babbler
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def collect
|
15
|
-
{:service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'MegaCli status'}
|
15
|
+
{ :service => plugin.service, :metric => shell(plugin.cmd).to_i, :description => 'MegaCli status' }
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -1,33 +1,37 @@
|
|
1
|
-
|
1
|
+
class Riemann::Babbler::Plugin::Memory < Riemann::Babbler::Plugin
|
2
2
|
|
3
|
-
|
3
|
+
def init
|
4
|
+
plugin.set_default(:service, 'memory')
|
5
|
+
plugin.states.set_default(:warning, 70)
|
6
|
+
plugin.states.set_default(:critical, 85)
|
7
|
+
end
|
4
8
|
|
5
9
|
def collect
|
6
|
-
m
|
7
|
-
x
|
10
|
+
m = File.read('/proc/meminfo').split(/\n/).inject({}) { |info, line|
|
11
|
+
x = line.split(/:?\s+/)
|
8
12
|
info[x[0]] = x[1].to_i
|
9
13
|
info
|
10
14
|
}
|
11
|
-
free
|
12
|
-
cached
|
15
|
+
free = m['MemFree'].to_i * 1024
|
16
|
+
cached =m['Cached'].to_i * 1024
|
13
17
|
buffers =m['Buffers'].to_i * 1024
|
14
|
-
total
|
15
|
-
used
|
18
|
+
total = m['MemTotal'].to_i * 1024
|
19
|
+
used = total - free
|
16
20
|
free_bc = free + buffers + cached
|
17
21
|
|
18
|
-
fraction
|
22
|
+
fraction = 1 - (free_bc.to_f / total)
|
19
23
|
swap_fraction = m['SwapTotal'] == 0 ? 0 : 1 - m['SwapFree'].to_f/m['SwapTotal']
|
20
24
|
|
21
25
|
desc = "#{shell('ps -eo pmem,pid,cmd --sort -pmem | head -3').chomp}"
|
22
26
|
[
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
{ :service => plugin.service + ' % free', :description => 'Memory usage, %', :metric => fraction.round(2) * 100 },
|
28
|
+
{ :service => plugin.service + ' % swap', :description => 'Swap usage, %', :metric => swap_fraction.round(2) * 100 },
|
29
|
+
{ :service => plugin.service + ' abs free', :description => "Memory free (kB)\n\n #{desc}", :metric => free, :state => 'ok' },
|
30
|
+
{ :service => plugin.service + ' abs total', :description => "Memory total (kB)\n\n #{desc}", :metric => total, :state => 'ok' },
|
31
|
+
{ :service => plugin.service + ' abs cached', :description => "Memory usage, cached (kB)\n\n #{desc}", :metric => cached, :state => 'ok' },
|
32
|
+
{ :service => plugin.service + ' abs buffers', :description => "Memory usage, buffers (kB)\n\n #{desc}", :metric => buffers, :state => 'ok' },
|
33
|
+
{ :service => plugin.service + ' abs used', :description => "Memory usage, used (kB)\n\n #{desc}", :metric => used, :state => 'ok' },
|
34
|
+
{ :service => plugin.service + ' abs free_bc', :description => "Memory usage with cache and buffers (kB)\n\n #{desc}", :metric => free_bc, :state => 'ok' }
|
31
35
|
]
|
32
36
|
end
|
33
37
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::Net < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::Net < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
WORDS = ['rx bytes',
|
4
4
|
'rx packets',
|
@@ -17,22 +17,24 @@ class Riemann::Babbler::Net < Riemann::Babbler
|
|
17
17
|
'tx compressed']
|
18
18
|
|
19
19
|
def init
|
20
|
+
plugin.set_default(:service, 'net')
|
20
21
|
plugin.set_default(:filter, ['rx bytes', 'rx errs', 'rx drop', 'tx bytes', 'tx errs', 'tx drop'])
|
21
22
|
end
|
22
23
|
|
23
24
|
def collect
|
24
|
-
f
|
25
|
+
f = File.read('/proc/net/dev')
|
25
26
|
status = Array.new
|
26
27
|
f.split("\n").each do |line|
|
27
28
|
iface = line.split(':')[0].strip
|
28
29
|
iface.gsub!(/\./, '_')
|
29
30
|
next unless line =~ /(\w*)\:\s*([\s\d]+)\s*/
|
30
31
|
WORDS.map do |service|
|
31
|
-
|
32
|
+
service
|
32
33
|
end.zip(
|
33
|
-
|
34
|
+
$2.split(/\s+/).map { |str| str.to_i }
|
34
35
|
).each do |service, value|
|
35
|
-
|
36
|
+
next unless plugin.filter.include? service
|
37
|
+
status << { :service => "#{plugin.service} #{service} #{iface}", :metric => value, :as_diff => true }
|
36
38
|
end
|
37
39
|
end
|
38
40
|
status
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::NetStat < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::NetStat < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
def init
|
4
4
|
plugin.set_default(:service, 'netstat')
|
@@ -18,16 +18,16 @@ class Riemann::Babbler::NetStat < Riemann::Babbler
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
filter += " \\) and not dst 127.0.0.1:*"
|
21
|
-
cmd
|
21
|
+
cmd = 'ss -t -4 -n state established ' + filter + ' | wc -l'
|
22
22
|
shell(cmd).to_i - 1
|
23
23
|
end
|
24
24
|
|
25
25
|
def collect
|
26
26
|
count = get_conn_count()
|
27
27
|
{
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
:service => "#{plugin.service} tcp #{plugin.ports.join(', ')}",
|
29
|
+
:metric => count,
|
30
|
+
:description => "count established connects: #{count} to ports #{plugin.ports.join(', ')}"
|
31
31
|
}
|
32
32
|
end
|
33
33
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Riemann::Babbler::Nginx < Riemann::Babbler
|
1
|
+
class Riemann::Babbler::Plugin::Nginx < Riemann::Babbler::Plugin
|
2
2
|
|
3
3
|
NGINX_STATUS_1 = %W(accepts handled requests)
|
4
4
|
NGINX_STATUS_2 = %W(reading writing waiting)
|
@@ -16,7 +16,7 @@ class Riemann::Babbler::Nginx < Riemann::Babbler
|
|
16
16
|
|
17
17
|
def collect
|
18
18
|
status = Array.new
|
19
|
-
lines
|
19
|
+
lines = rest_get(plugin.status_url).split("\n")
|
20
20
|
lines[2].scan(/\d+/).each_with_index do |value, index|
|
21
21
|
status << { :service => plugin.service + " #{NGINX_STATUS_1[index]}", :metric => value.to_i, :as_diff => true }
|
22
22
|
end
|