lib/riemann/babbler/plugins/runit.rb in riemann-babbler-1.2.0 vs lib/riemann/babbler/plugins/runit.rb in riemann-babbler-1.2.1

- old
+ new

@@ -1,32 +1,38 @@ class Riemann::Babbler::Runit < Riemann::Babbler def init plugin.set_default(:service, 'runit') - plugin.set_default(:not_monit, []) + plugin.set_default(:not_monit, ['riemann-client']) + plugin.set_default(:warning_uptime, 10) plugin.set_default(:interval, 60) end def run_plugin Dir.exists? '/etc/service' - @status_history = Array.new end + # service uptime + def uptime(service) + pid_file = File.join(service, 'supervise', 'pid') + return 0 unless File.exist?(pid_file) + Time.now.to_i - File.mtime(pid_file).to_i + end + def read_run_status status = Array.new Dir.glob('/etc/service/*').each do |srv| next if plugin.not_monit.include? srv human_srv = ' ' + srv.gsub(/\/etc\/service\//, '') stat_file = File.join(srv, 'supervise', 'stat') next unless File.exists? stat_file - if File.read( stat_file ).strip == 'run' - @status_history.delete human_srv - status << {:service => plugin.service + human_srv , :state => 'ok', :description => "runit service #{human_srv} running"} + srv_uptime = uptime(srv) + if (File.read( stat_file ).strip == 'run') && (srv_uptime > plugin.interval) + status << {:service => plugin.service + human_srv , :state => 'ok', :description => "runit service #{human_srv} running", :metric => srv_uptime} + elsif (File.read( stat_file ).strip == 'run') && (srv_uptime < plugin.warning_uptime) + status << {:service => plugin.service + human_srv , :state => 'warning', :description => "runit service #{human_srv} small uptime", :metric => srv_uptime} else - if @status_history.include? human_srv - status << {:service => plugin.service + human_srv , :state => 'critical', :description => "runit service #{human_srv} not running"} - end - @status_history << human_srv unless @status_history.include? human_srv + status << {:service => plugin.service + human_srv , :state => 'critical', :description => "runit service #{human_srv} not running", :metric => srv_uptime} end end status end