Sha256: f9f5137cae11eef350d05b61d33d4c03e7ea9b7fe97746a0e70f531e6d86e7bb
Contents?: true
Size: 1.43 KB
Versions: 9
Compression:
Stored size: 1.43 KB
Contents
module WatchmonkeyCli module Checkers class UnixLoad < Checker self.checker_name = "unix_load" 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 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? # plotter support 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 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 end end end
Version data entries
9 entries across 9 versions & 1 rubygems