riemann-babbler 1.2.6 → 1.2.7
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/lib/riemann/babbler/plugins/runit.rb +34 -8
- data/lib/riemann/babbler/version.rb +1 -1
- metadata +1 -1
|
@@ -3,8 +3,9 @@ class Riemann::Babbler::Runit < Riemann::Babbler
|
|
|
3
3
|
def init
|
|
4
4
|
plugin.set_default(:service, 'runit')
|
|
5
5
|
plugin.set_default(:not_monit, ['riemann-client'])
|
|
6
|
-
plugin.set_default(:uptime, 10)
|
|
7
6
|
plugin.set_default(:interval, 60)
|
|
7
|
+
|
|
8
|
+
@status_history = Array.new
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def run_plugin
|
|
@@ -18,19 +19,44 @@ class Riemann::Babbler::Runit < Riemann::Babbler
|
|
|
18
19
|
Time.now.to_i - File.mtime(pid_file).to_i
|
|
19
20
|
end
|
|
20
21
|
|
|
22
|
+
def runned?(service)
|
|
23
|
+
stat_file = File.join(service, 'supervise', 'stat')
|
|
24
|
+
return false unless File.exists?(stat_file)
|
|
25
|
+
File.read( stat_file ).strip == 'run'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def human_srv(service)
|
|
29
|
+
service.gsub(/\/etc\/service\//, '')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def not_monit?(service)
|
|
33
|
+
plugin.not_monit.include? human_srv(service)
|
|
34
|
+
end
|
|
35
|
+
|
|
21
36
|
def read_run_status
|
|
22
37
|
status = Array.new
|
|
23
38
|
Dir.glob('/etc/service/*').each do |srv|
|
|
24
|
-
|
|
25
|
-
next if
|
|
26
|
-
stat_file = File.join(srv, 'supervise', 'stat')
|
|
27
|
-
next unless File.exists? stat_file
|
|
39
|
+
|
|
40
|
+
next if not_monit?(srv)
|
|
28
41
|
srv_uptime = uptime(srv)
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
srv_runned = runned?(srv)
|
|
43
|
+
srv_name = human_srv(srv)
|
|
44
|
+
|
|
45
|
+
# сервис запущен и работает дольше чем мы приходили к нему в прошлый раз
|
|
46
|
+
if srv_runned && srv_uptime > plugin.interval
|
|
47
|
+
@status_history.delete(srv_name)
|
|
48
|
+
status << {:service => plugin.service + ' ' + srv_name , :state => 'ok', :description => "runit service #{srv_name} running", :metric => srv_uptime}
|
|
31
49
|
else
|
|
32
|
-
|
|
50
|
+
# сервис запущен но работает подозрительно мало, но последний раз замечен не был
|
|
51
|
+
if srv_uptime < plugin.interval && srv_runned && !@status_history.include?(srv_name)
|
|
52
|
+
# просто его запоминаем
|
|
53
|
+
@status_history << srv_name
|
|
54
|
+
else
|
|
55
|
+
# во всех остальных случаях сообщаем о проблеме
|
|
56
|
+
status << {:service => plugin.service + ' ' + srv_name , :state => 'critical', :description => "runit service #{srv_name} not running", :metric => srv_uptime}
|
|
57
|
+
end
|
|
33
58
|
end
|
|
59
|
+
|
|
34
60
|
end
|
|
35
61
|
status
|
|
36
62
|
end
|