Class: Perus::Pinger::Process

Inherits:
Command
  • Object
show all
Defined in:
lib/perus/pinger/metrics/process.rb

Instance Attribute Summary

Attributes inherited from Command

#id, #options

Instance Method Summary collapse

Methods inherited from Command

abstract!, abstract?, #cleanup, #darwin?, description, human_name, inherited, #initialize, metric!, metric?, option, options, #shell, subclasses

Constructor Details

This class inherits a constructor from Perus::Pinger::Command

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/perus/pinger/metrics/process.rb', line 12

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