class RorVsWild::Metrics::Cpu
Attributes
count[R]
idle[R]
load_average[R]
stolen[R]
system[R]
user[R]
waiting[R]
Public Class Methods
new()
click to toggle source
# File lib/rorvswild/metrics/cpu.rb, line 9 def initialize @old_stat = Stat.read end
Public Instance Methods
update()
click to toggle source
# 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