class PiSys::Uptime

Constants

KEY
VARIATIONS

Public Class Methods

new() click to toggle source
Calls superclass method PiSys::Stats::new
# File lib/pi-sys/stats/uptime.rb, line 7
def initialize
  super(KEY, VARIATIONS)
end

Public Instance Methods

fetch() click to toggle source
Calls superclass method PiSys::Stats#fetch
# File lib/pi-sys/stats/uptime.rb, line 11
def fetch
  super

  output = run_command 'uptime'

  if output
    to_hash(KEY, output) do |data|
      index_of_reference = data.index('user,') || data.index('users,')
      {
        time: data[0],
        up: data[2..index_of_reference-2].join(' ').gsub(/(,$)/i,''),
        users: data[index_of_reference-1],
        load_average: {
          one: data[data.length-3].gsub(',',''),
          five: data[data.length-2].gsub(',',''),
          fiftheen: data[data.length-1].gsub(',','')
        }
      }
    end
  end

  STATS[KEY]
end