Class: CPU::Load
Instance Attribute Summary
Attributes included from Shared
Instance Method Summary collapse
-
#initialize ⇒ Load
constructor
Create a new CPU::Load instance providing CPU load averages data.
- #inspect ⇒ Object (also: #to_s)
-
#last_15_minutes ⇒ Object
Return the load average for the last 15 minutes.
-
#last_15_minutes_by_core ⇒ Object
Return the load average for the last 15 minutes, divided by the number of cores.
-
#last_15_minutes_by_processor ⇒ Object
Return the load average for the last 15 minutes, divided by the number of processors.
-
#last_5_minutes ⇒ Object
Return the load average for the last 5 minutes.
-
#last_5_minutes_by_core ⇒ Object
Return the load average for the last 5 minutes, divided by the number of cores.
-
#last_5_minutes_by_processor ⇒ Object
Return the load average for the last 5 minutes, divided by the number of processors.
-
#last_minute ⇒ Object
Return the load average for the last minute.
-
#last_minute_by_core ⇒ Object
Return the load average for the last minute, divided by the number of cores.
-
#last_minute_by_processor ⇒ Object
Return the load average for the last minute, divided by the number of processors.
-
#to_a ⇒ Object
Return 1 minute, 5 minutes, and 15 minutes load data as an array of floating point values.
Constructor Details
#initialize ⇒ Load
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
#inspect ⇒ Object Also known as: to_s
69 70 71 |
# File 'lib/cpu/load.rb', line 69 def inspect "#<#{self.class}: #{to_a * ' '}>" end |
#last_15_minutes ⇒ Object
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_core ⇒ Object
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_processor ⇒ Object
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_minutes ⇒ Object
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_core ⇒ Object
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_processor ⇒ Object
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_minute ⇒ Object
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_core ⇒ Object
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_processor ⇒ Object
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_a ⇒ Object
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 |