Sha256: 7b7f59899860beafcd8f1e8859e776b2f351042aae5a5fce6d5d32a29bae8c14

Contents?: true

Size: 1.04 KB

Versions: 41

Compression:

Stored size: 1.04 KB

Contents

module Perus::Pinger
    class Process < Command
        description 'Measures percentage of RAM and CPU used by the process
                     specified by "process_path". The results are returned to
                     the server under 2 metrics called "cpu_{name}" and
                     "mem_{name}". Valid values for "process_path" are
                     contained in the pinger config file.'
        option :process_path, restricted: true
        option :name
        metric!

        def run
            path = options.process_path.gsub("/", "\\/")
            cpu, mem = shell("ps aux | awk '/#{path}/ {cpu += $3; mem += $4} END {print cpu, mem;}'").split

            if darwin?
                core_count = shell('sysctl -n hw.ncpu')
            else
                core_count = shell("cat /proc/cpuinfo | grep processor | awk '{count += 1} END {print count}'")
            end

            {
                "cpu_#{options.name}" => cpu.to_f / core_count.to_i,
                "mem_#{options.name}" => mem.to_f
            }
        end
    end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
perus-0.1.3 lib/perus/pinger/metrics/process.rb