class RorVsWild::Metrics::Cpu::Stat
def self.parse(string)
def self.parse(string) for row in string.lines if row.start_with?("cpu ") array = row.split[1..-1].map(&:to_i)[0,10] array.fill(0, array.size, 10 - array.size) if array.size < 10 return new(*array) end end nil end
def self.read
def self.read parse(File.read("/proc/stat")) if File.readable?("/proc/stat") end
def initialize(user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice)
def initialize(user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice) @user = user @nice = nice @system = system @idle = idle @iowait = iowait @irq = irq @softirq = softirq @steal = steal @guest = guest @guest_nice = guest_nice @total = user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice end