module Vmstat::Solaris::ClassMethods

Public Instance Methods

boot_time() click to toggle source
# File lib/vmstat/solaris.rb, line 18
def boot_time
  Time.at(%x`kstat -p unix:::boot_time`.strip.split(/\s+/).last.to_i)
end
cpu() click to toggle source
# File lib/vmstat/solaris.rb, line 4
def cpu
  kstat = %x`kstat -p "cpu_stat:::/idle|kernel|user/"`
  cpus = Hash.new { |h, k| h[k] = Hash.new }

  kstat.lines.each do |line|
    _, cpu, _, key, value = line.strip.split(/:|\s+/)
    cpus[cpu.to_i][key] = value
  end

  cpus.map do |num, v|
    Cpu.new(num, v["user"].to_i, v["kernel"].to_i, 0, v["idle"].to_i)
  end
end
memory() click to toggle source
# File lib/vmstat/solaris.rb, line 22
def memory
  kstat = %x`kstat -p -n system_pages`
  values = Hash.new

  kstat.lines.each do |line|
    _, _, _, key, value = line.strip.split(/:|\s+/)
    values[key] = value
  end

  total = values['pagestotal'].to_i
  free = values['pagesfree'].to_i
  locked = values['pageslocked'].to_i

  Memory.new(Vmstat.pagesize,
             locked, # wired
             total - free - locked, # active
             0, # inactive
             free, # free
             0, #pageins
             0) #pageouts
end
network_interfaces() click to toggle source
# File lib/vmstat/solaris.rb, line 44
def network_interfaces
  kstat = %x`kstat -p link:::`
  itfs = Hash.new { |h, k| h[k] = Hash.new }

  kstat.lines.each do |line|
    _, _, name, key, value = line.strip.split(/:|\s+/)
    itfs[name.to_sym][key] = value
  end

  itfs.map do |k, v|
    NetworkInterface.new(k, v['rbytes64'].to_i,
                            v['ierrors'].to_i,
                            0,
                            v['obytes64'].to_i,
                            v['oerrors'].to_i,
                            NetworkInterface::ETHERNET_TYPE)
  end
end