lib/perus/pinger/metrics/process.rb in perus-0.1.2 vs lib/perus/pinger/metrics/process.rb in perus-0.1.3
- old
+ new
@@ -8,15 +8,16 @@
option :process_path, restricted: true
option :name
metric!
def run
- path = options.process_path.gsub("/", "\\\\\\/")
- cpu, mem = `ps aux | awk '/#{path}/ {cpu += $3; mem += $4} END {print cpu, mem;}'`.split
- if `uname -s`.strip == 'Darwin'
- core_count = `sysctl -n hw.ncpu`
+ 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 = `cat /proc/cpuinfo | grep processor | awk '{count += 1} END {print count}'`
+ 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