Sha256: b0cb9a9b708e7cac82fa166dd64b1d033a2b4f0718846a7b5271ed6c5071a364
Contents?: true
Size: 1.55 KB
Versions: 3
Compression:
Stored size: 1.55 KB
Contents
#!/usr/bin/env ruby # Reports running process count to riemann. require File.expand_path('../../lib/riemann/tools', __FILE__) class Riemann::Tools::Proc include Riemann::Tools opt :proc_regex, "regular expression that matches the process to be monitored", type: :string opt :proc_min_critical, "running process count minimum", :default => 1 opt :proc_max_critical, "running process count maximum", :default => 1 def initialize @limits = { :critical => { :min => opts[:proc_min_critical], :max => opts[:proc_max_critical] } } abort "FATAL: specify a process regular expression, see --help for usage" unless opts[:proc_regex] ostype = `uname -s`.chomp.downcase puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == "linux" @check = method :linux_proc end def alert(service, state, metric, description) report( :service => service.to_s, :state => state.to_s, :metric => metric.to_f, :description => description ) end def linux_proc process = opts[:proc_regex] found = `ps axo args | grep '#{process}' | grep -v grep | grep -v riemann-proc` running = found.count("\n") if running > @limits[:critical][:max] or running < @limits[:critical][:min] alert "proc #{process}", :critical, running, "process #{process} is running #{running} instances:\n" + found else alert "proc #{process}", :ok, running, "process #{process} is running #{running} instances:\n" + found end end def tick @check.call end end Riemann::Tools::Proc.run
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
riemann-tools-0.2.8 | bin/riemann-proc |
riemann-tools-0.2.7 | bin/riemann-proc |
riemann-tools-0.2.6 | bin/riemann-proc |