Class: Perus::Pinger::CPU

Inherits:
Command
  • Object
show all
Defined in:
lib/perus/pinger/metrics/cpu.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



7
8
9
10
11
12
13
14
15
# File 'lib/perus/pinger/metrics/cpu.rb', line 7

def run
    if darwin?
        percent = 100 - shell('iostat dxxvdfs -n 0').split("\n")[2].split[2].to_i
    else
        percent = shell("grep 'cpu ' /proc/stat | awk '{print (1 - ($5 / ($2+$3+$4+$5+$6+$7+$8)))*100}'")
    end
    
    {cpu_all: percent.to_f}
end