class CpuStats
CPU stat collection and calculation
Constants
- CLASSES
Attributes
later[R]
now[R]
Public Instance Methods
collect(sleep_time = 5)
click to toggle source
# File lib/check_cpu_steal/cpu_stats.rb, line 18 def collect(sleep_time = 5) @now = stats(read_proc) sleep sleep_time @later = stats(read_proc) @now[:total] = @now.values.inject(:+) @later[:total] = @later.values.inject(:+) end
read_proc(file = '/proc/stat')
click to toggle source
# File lib/check_cpu_steal/cpu_stats.rb, line 26 def read_proc(file = '/proc/stat') File.foreach(file).first end
stat_diff(stat_name)
click to toggle source
# File lib/check_cpu_steal/cpu_stats.rb, line 37 def stat_diff(stat_name) @later[stat_name] - @now[stat_name] end
stat_pct(stat_name)
click to toggle source
# File lib/check_cpu_steal/cpu_stats.rb, line 41 def stat_pct(stat_name) stat_diff(stat_name) / stat_diff(:total) end
stats(info)
click to toggle source
# File lib/check_cpu_steal/cpu_stats.rb, line 30 def stats(info) stats = info.split(/\s+/) stats.shift stats.map!(&:to_f) Hash[CLASSES.zip(stats)] end