Class: BaselineRedAgent::Plugin::System::Cpu
- Defined in:
- lib/baseline_red_agent/plugin/system/cpu.rb
Instance Attribute Summary collapse
-
#last ⇒ Object
Returns the value of attribute last.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize ⇒ Cpu
constructor
A new instance of Cpu.
Methods inherited from Base
Constructor Details
#initialize ⇒ Cpu
Returns a new instance of Cpu.
10 11 12 13 |
# File 'lib/baseline_red_agent/plugin/system/cpu.rb', line 10 def initialize self.last = Vmstat.snapshot.cpus super end |
Instance Attribute Details
#last ⇒ Object
Returns the value of attribute last.
8 9 10 |
# File 'lib/baseline_red_agent/plugin/system/cpu.rb', line 8 def last @last end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/baseline_red_agent/plugin/system/cpu.rb', line 15 def call cpus = Vmstat.snapshot.cpus metrics = cpus.each_with_index.flat_map {|cpu, index| total = (cpu.idle + cpu.nice + cpu.system + cpu.user) - (last[index].idle + last[index].nice + last[index].system + last[index].user) [ ["system.cpu.idle", (cpu.idle - last[index].idle).to_f / total.to_f * 100.to_f, { "num" => cpu.num }], ["system.cpu.nice", (cpu.nice - last[index].nice).to_f / total.to_f * 100.to_f, { "num" => cpu.num }], ["system.cpu.system", (cpu.system - last[index].system).to_f / total.to_f * 100.to_f, { "num" => cpu.num }], ["system.cpu.user", (cpu.user - last[index].user).to_f / total.to_f * 100.to_f, { "num" => cpu.num }] ] } self.last = cpus metrics end |