Class: ProcParser::Loadavg

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(loadavg_file = '/proc/loadavg') ⇒ Loadavg

Returns a new instance of Loadavg.

Raises:



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_pidObject

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

#loadavg1Object

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

#loadavg15Object

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

#loadavg5Object

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_queueObject

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_tasksObject

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