Class: RorVsWild::Metrics::Cpu
- Inherits:
-
Object
- Object
- RorVsWild::Metrics::Cpu
- Defined in:
- lib/rorvswild/metrics/cpu.rb
Defined Under Namespace
Classes: Stat
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#idle ⇒ Object
readonly
Returns the value of attribute idle.
-
#load_average ⇒ Object
readonly
Returns the value of attribute load_average.
-
#stolen ⇒ Object
readonly
Returns the value of attribute stolen.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#waiting ⇒ Object
readonly
Returns the value of attribute waiting.
Instance Method Summary collapse
-
#initialize ⇒ Cpu
constructor
A new instance of Cpu.
- #update ⇒ Object
Constructor Details
#initialize ⇒ Cpu
Returns a new instance of Cpu.
9 10 11 |
# File 'lib/rorvswild/metrics/cpu.rb', line 9 def initialize @old_stat = Stat.read end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
7 8 9 |
# File 'lib/rorvswild/metrics/cpu.rb', line 7 def count @count end |
#idle ⇒ Object (readonly)
Returns the value of attribute idle.
6 7 8 |
# File 'lib/rorvswild/metrics/cpu.rb', line 6 def idle @idle end |
#load_average ⇒ Object (readonly)
Returns the value of attribute load_average.
7 8 9 |
# File 'lib/rorvswild/metrics/cpu.rb', line 7 def load_average @load_average end |
#stolen ⇒ Object (readonly)
Returns the value of attribute stolen.
6 7 8 |
# File 'lib/rorvswild/metrics/cpu.rb', line 6 def stolen @stolen end |
#system ⇒ Object (readonly)
Returns the value of attribute system.
6 7 8 |
# File 'lib/rorvswild/metrics/cpu.rb', line 6 def system @system end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/rorvswild/metrics/cpu.rb', line 6 def user @user end |
#waiting ⇒ Object (readonly)
Returns the value of attribute waiting.
6 7 8 |
# File 'lib/rorvswild/metrics/cpu.rb', line 6 def waiting @waiting end |
Instance Method Details
#update ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rorvswild/metrics/cpu.rb', line 13 def update if @old_stat && (new_stat = Stat.read) if (total = new_stat.total - @old_stat.total) > 0 @user = (new_stat.user - @old_stat.user) * 100 / total @system = (new_stat.system - @old_stat.system) * 100 / total @idle = (new_stat.idle - @old_stat.idle) * 100 / total @waiting = (new_stat.iowait - @old_stat.iowait) * 100 / total @stolen = (new_stat.steal - @old_stat.steal) * 100 / total @old_stat = new_stat end end @load_average = File.read("/proc/loadavg").to_f if File.readable?("/proc/loadavg") @count = `nproc`.to_i rescue nil end |