Class: WatchmonkeyCli::Checkers::UnixLoad
Instance Attribute Summary
#app
Instance Method Summary
collapse
#_tolog, checker_name, checker_name=, #debug, descendants, #error, #info, inherited, #init, #initialize, #local, #rsafe, #safe, #spawn_sub, #start, #stop
Instance Method Details
#_parse_response(res) ⇒ Object
32
33
34
|
# File 'lib/watchmonkey_cli/checkers/unix_load.rb', line 32
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
24
25
26
27
28
29
30
|
# 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?
app.fire :plotter_push, self, host, {
load1: ld[0], limit1: opts[:limits][0],
load5: ld[1], limit5: opts[:limits][1],
load15: ld[2], limit15: opts[:limits][2],
}
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
|