Class: CPU::Load

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/cpu/load.rb

Instance Attribute Summary

Attributes included from Shared

#num_cores, #num_processors

Instance Method Summary collapse

Constructor Details

#initializeLoad

Create a new CPU::Load instance providing CPU load averages data.



6
7
8
9
10
# File 'lib/cpu/load.rb', line 6

def initialize
  @load_data = File.open('/proc/loadavg') do |loadavg|
    loadavg.readline.split(/\s+/).first(3).map(&:to_f)
  end
end

Instance Method Details

#inspectObject Also known as: to_s



69
70
71
# File 'lib/cpu/load.rb', line 69

def inspect
  "#<#{self.class}: #{to_a * ' '}>"
end

#last_15_minutesObject

Return the load average for the last 15 minutes.



47
48
49
# File 'lib/cpu/load.rb', line 47

def last_15_minutes
  @load_data[2]
end

#last_15_minutes_by_coreObject

Return the load average for the last 15 minutes, divided by the number of cores.



53
54
55
# File 'lib/cpu/load.rb', line 53

def last_15_minutes_by_core
  last_15_minutes / num_cores
end

#last_15_minutes_by_processorObject

Return the load average for the last 15 minutes, divided by the number of processors.



59
60
61
# File 'lib/cpu/load.rb', line 59

def last_15_minutes_by_processor
  last_15_minutes / num_processors
end

#last_5_minutesObject

Return the load average for the last 5 minutes.



30
31
32
# File 'lib/cpu/load.rb', line 30

def last_5_minutes
  @load_data[1]
end

#last_5_minutes_by_coreObject

Return the load average for the last 5 minutes, divided by the number of cores.



36
37
38
# File 'lib/cpu/load.rb', line 36

def last_5_minutes_by_core
  last_5_minutes / num_cores
end

#last_5_minutes_by_processorObject

Return the load average for the last 5 minutes, divided by the number of processors.



42
43
44
# File 'lib/cpu/load.rb', line 42

def last_5_minutes_by_processor
  last_5_minutes / num_processors
end

#last_minuteObject

Return the load average for the last minute.



13
14
15
# File 'lib/cpu/load.rb', line 13

def last_minute
  @load_data[0]
end

#last_minute_by_coreObject

Return the load average for the last minute, divided by the number of cores.



19
20
21
# File 'lib/cpu/load.rb', line 19

def last_minute_by_core
  last_minute / num_cores
end

#last_minute_by_processorObject

Return the load average for the last minute, divided by the number of processors.



25
26
27
# File 'lib/cpu/load.rb', line 25

def last_minute_by_processor
  last_minute / num_processors
end

#to_aObject

Return 1 minute, 5 minutes, and 15 minutes load data as an array of floating point values.



65
66
67
# File 'lib/cpu/load.rb', line 65

def to_a
  @load_data.dup
end