Sha256: e91a04cbf84e5b3ab38f9aa3eeb26a6e643a8c6cb5643bf2c023d0da55961e2d

Contents?: true

Size: 1.24 KB

Versions: 17

Compression:

Stored size: 1.24 KB

Contents

module WatchmonkeyCli
  module Checkers
    class UnixMemory < Checker
      self.checker_name = "unix_memory"

      def enqueue host, opts = {}
        opts = { min_percent: 25 }.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 = "cat /proc/meminfo"
        result.result = host.exec(result.command)
        result.data = _parse_response(result.result)

        if !result.data
          result.error! result.result
        else
          result.error! "memory is low (limit is min. #{opts[:min_percent]}%, got #{result.data["free"]}%)" if opts[:min_percent] && result.data["free"] < opts[:min_percent]
        end
      end

      def _parse_response res
        return false if res.downcase["no such file"]
        {}.tap do |r|
          res.strip.split("\n").each do |line|
            chunks = line.split(":").map(&:strip)
            r[chunks[0]] = chunks[1].to_i
          end
          r["free"] = ((r["MemFree"].to_i + r["Buffers"].to_i + r["Cached"].to_i) / r["MemTotal"].to_f * 100).round(2)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
watchmonkey_cli-1.12.0 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.11.0 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.10.0 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.9.1 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.9.0 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8.6 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8.5 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8.4 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8.3 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8.2 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8.1 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.8 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.7.1 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.7 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.6 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.5 lib/watchmonkey_cli/checkers/unix_memory.rb
watchmonkey_cli-1.4 lib/watchmonkey_cli/checkers/unix_memory.rb