Sha256: ce78bc97a9dcb0e710a652b39e6c4b4961a144762cc67264b9af4e0171a57713

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

class Riemann::Babbler::Runit < Riemann::Babbler

  def init
    plugin.set_default(:service, 'runit')
    plugin.set_default(:not_monit, ['riemann-client'])
    plugin.set_default(:uptime, 10)
    plugin.set_default(:interval, 60)
  end

  def run_plugin
    Dir.exists? '/etc/service'
  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
      srv_uptime = uptime(srv)
      if (File.read( stat_file ).strip == 'run') && (srv_uptime > plugin.uptime)
        status << {:service => plugin.service + human_srv , :state => 'ok', :description => "runit service #{human_srv} running", :metric => srv_uptime}
      else
        status << {:service => plugin.service + human_srv , :state => 'critical', :description => "runit service #{human_srv} not running", :metric => srv_uptime}
      end
    end
    status
  end

  def collect
    read_run_status
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-babbler-1.2.2 lib/riemann/babbler/plugins/runit.rb