class ProcParser::Loadavg

Attributes

last_pid[RW]

This class read load average information from the /proc/loadavg file.

loadavg1[RW]

This class read load average information from the /proc/loadavg file.

loadavg15[RW]

This class read load average information from the /proc/loadavg file.

loadavg5[RW]

This class read load average information from the /proc/loadavg file.

run_queue[RW]

This class read load average information from the /proc/loadavg file.

total_tasks[RW]

This class read load average information from the /proc/loadavg file.

Public Class Methods

new(loadavg_file = '/proc/loadavg') click to toggle source
# 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