Class: ProcParser::Loadavg
- Inherits:
-
Object
- Object
- ProcParser::Loadavg
- Defined in:
- lib/proc_parser/loadavg.rb
Constant Summary collapse
- @@attributes =
{ loadavg1: 0, loadavg5: 1, loadavg15: 2, run_queue: 3, total_tasks: 4, last_pid: 5, }
Instance Attribute Summary collapse
-
#last_pid ⇒ Object
This class read load average information from the /proc/loadavg file.
-
#loadavg1 ⇒ Object
This class read load average information from the /proc/loadavg file.
-
#loadavg15 ⇒ Object
This class read load average information from the /proc/loadavg file.
-
#loadavg5 ⇒ Object
This class read load average information from the /proc/loadavg file.
-
#run_queue ⇒ Object
This class read load average information from the /proc/loadavg file.
-
#total_tasks ⇒ Object
This class read load average information from the /proc/loadavg file.
Instance Method Summary collapse
-
#initialize(loadavg_file = '/proc/loadavg') ⇒ Loadavg
constructor
A new instance of Loadavg.
Constructor Details
#initialize(loadavg_file = '/proc/loadavg') ⇒ Loadavg
Returns a new instance of Loadavg.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/proc_parser/loadavg.rb', line 17 def initialize(loadavg_file = '/proc/loadavg') raise NoProcData, "This system doesn't have /proc/loadavg data." if !File.exist?(loadavg_file) File.open(loadavg_file, 'r') do |file| firstline = file.readline.strip.squeeze(' ').sub('/', ' ').split(' ') raise NoProcData, 'Unknown format for /proc/loadavg' if firstline.count != 6 @@attributes.each do |attribute, index| val = if index <= 2 firstline[index].to_f else firstline[index].to_i end instance_variable_set("@#{attribute}", val) end end end |
Instance Attribute Details
#last_pid ⇒ Object
This class read load average information from the /proc/loadavg file.
7 8 9 |
# File 'lib/proc_parser/loadavg.rb', line 7 def last_pid @last_pid end |
#loadavg1 ⇒ Object
This class read load average information from the /proc/loadavg file.
7 8 9 |
# File 'lib/proc_parser/loadavg.rb', line 7 def loadavg1 @loadavg1 end |
#loadavg15 ⇒ Object
This class read load average information from the /proc/loadavg file.
7 8 9 |
# File 'lib/proc_parser/loadavg.rb', line 7 def loadavg15 @loadavg15 end |
#loadavg5 ⇒ Object
This class read load average information from the /proc/loadavg file.
7 8 9 |
# File 'lib/proc_parser/loadavg.rb', line 7 def loadavg5 @loadavg5 end |
#run_queue ⇒ Object
This class read load average information from the /proc/loadavg file.
7 8 9 |
# File 'lib/proc_parser/loadavg.rb', line 7 def run_queue @run_queue end |
#total_tasks ⇒ Object
This class read load average information from the /proc/loadavg file.
7 8 9 |
# File 'lib/proc_parser/loadavg.rb', line 7 def total_tasks @total_tasks end |