Module: Vmstat::Solaris::ClassMethods

Included in:
Vmstat::Solaris
Defined in:
lib/vmstat/solaris.rb

Instance Method Summary collapse

Instance Method Details

#boot_timeObject



18
19
20
# File 'lib/vmstat/solaris.rb', line 18

def boot_time
  Time.at(`kstat -p unix:::boot_time`.strip.split(/\s+/).last.to_i)
end

#cpuObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/vmstat/solaris.rb', line 4

def cpu
  kstat = `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

#memoryObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vmstat/solaris.rb', line 22

def memory
  kstat = `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_interfacesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vmstat/solaris.rb', line 44

def network_interfaces
  kstat = `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