Class: WatchmonkeyCli::Checkers::UnixLoad

Inherits:
WatchmonkeyCli::Checker show all
Defined in:
lib/watchmonkey_cli/checkers/unix_load.rb

Constant Summary

Constants included from Helper

Helper::BYTE_UNITS

Instance Attribute Summary

Attributes inherited from WatchmonkeyCli::Checker

#app

Instance Method Summary collapse

Methods inherited from WatchmonkeyCli::Checker

#_tolog, #blank_config, checker_name, checker_name=, #debug, descendants, #error, #info, inherited, #init, #initialize, #local, maxrt, maxrt=, #rsafe, #safe, #spawn_sub, #start, #stop

Methods included from Helper

#human_filesize, #human_number, #human_seconds

Constructor Details

This class inherits a constructor from WatchmonkeyCli::Checker

Instance Method Details

#_parse_response(res) ⇒ Object



25
26
27
# File 'lib/watchmonkey_cli/checkers/unix_load.rb', line 25

def _parse_response res
  res.match(/load average(?:s)?: (?:([\d\.]+), ([\d\.]+), ([\d\.]+))|(?:([\d,]+) ([\d\,]+) ([\d\,]+))/i)[1..-1].reject(&:blank?).map{|v| v.gsub(",", ".").to_f }
end

#check!(result, host, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/watchmonkey_cli/checkers/unix_load.rb', line 13

def check! result, host, opts = {}
  result.command = "uptime"
  result.result = host.exec(result.command)
  ld = result.data = _parse_response(result.result)

  emsg = []
  emsg << "load1 is to high (limit1 is #{opts[:limits][0]}, load1 is #{ld[0]})" if ld[0] > opts[:limits][0]
  emsg << "load5 is to high (limit5 is #{opts[:limits][1]}, load5 is #{ld[1]})" if ld[1] > opts[:limits][1]
  emsg << "load15 is to high (limit15 is #{opts[:limits][2]}, load15 is #{ld[2]})" if ld[2] > opts[:limits][2]
  result.error!(emsg.join("\n\t")) if emsg.any?
end

#enqueue(host, opts = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/watchmonkey_cli/checkers/unix_load.rb', line 6

def enqueue host, opts = {}
  opts = { limits: [4, 2, 1.5] }.merge(opts)
  host = app.fetch_connection(:loopback, :local) if !host || host == :local
  host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
  app.enqueue(self, host, opts)
end