class Riemann::Tools::Fd
Public Class Methods
new()
click to toggle source
Calls superclass method
Riemann::Tools::new
# File lib/riemann/tools/fd.rb, line 18 def initialize super @limits = { fd: { critical: opts[:fd_sys_critical], warning: opts[:fd_sys_warning] }, process: { critical: opts[:fd_proc_critical], warning: opts[:fd_proc_warning] }, } ostype = `uname -s`.chomp.downcase case ostype when 'freebsd' @fd = method :freebsd_fd else puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == 'linux' @fd = method :linux_fd end end
Public Instance Methods
alert(service, state, metric, description)
click to toggle source
# File lib/riemann/tools/fd.rb, line 35 def alert(service, state, metric, description) report( service: service.to_s, state: state.to_s, metric: metric.to_f, description: description, ) end
freebsd_fd()
click to toggle source
# File lib/riemann/tools/fd.rb, line 44 def freebsd_fd sys_used = Integer(`sysctl -n kern.openfiles`) if sys_used > @limits[:fd][:critical] alert 'fd sys', :critical, sys_used, "system is using #{sys_used} fds" elsif sys_used > @limits[:fd][:warning] alert 'fd sys', :warning, sys_used, "system is using #{sys_used} fds" else alert 'fd sys', :ok, sys_used, "system is using #{sys_used} fds" end end
linux_fd()
click to toggle source
# File lib/riemann/tools/fd.rb, line 55 def linux_fd sys_used = Integer(`lsof | wc -l`) if sys_used > @limits[:fd][:critical] alert 'fd sys', :critical, sys_used, "system is using #{sys_used} fds" elsif sys_used > @limits[:fd][:warning] alert 'fd sys', :warning, sys_used, "system is using #{sys_used} fds" else alert 'fd sys', :ok, sys_used, "system is using #{sys_used} fds" end opts[:processes]&.each do |process| used = Integer(`lsof -p #{process} | wc -l`) name, _pid = `ps axo comm,pid | grep -w #{process}`.split if used > @limits[:process][:critical] alert "fd #{name} #{process}", :critical, used, "process #{name} #{process} is using #{used} fds" elsif used > @limits[:process][:warning] alert "fd #{name} #{process}", :warning, used, "process #{name} #{process} is using #{used} fds" else alert "fd #{name} #{process}", :ok, used, "process #{name} #{process} is using #{used} fds" end end end
tick()
click to toggle source
# File lib/riemann/tools/fd.rb, line 78 def tick @fd.call end