Skip to content

Commit 0478732

Browse files
author
Vincent Landgraf
committed
#10 memory, cpu and network interfaces support
(based on shellout - but no boot time or disks)
1 parent d5319fa commit 0478732

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

lib/vmstat.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ def self.loopback_devices
101101
elsif RUBY_PLATFORM =~ /(net|open)bsd/
102102
# command based implementation of mem, net, cpu
103103
require "vmstat/netopenbsd"
104+
elsif RUBY_PLATFORM =~ /solaris|smartos/
105+
# command based implementation of mem, net, cpu
106+
require "vmstat/solaris"
104107
end

lib/vmstat/solaris.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Vmstat
2+
def self.cpu
3+
mpstat = `mpstat 1 1`.lines
4+
mpstat.shift # ignore header
5+
mpstat.map do |line|
6+
num, *rest, user, sys, _, idle = line.strip.split(/\s+/)
7+
Cpu.new(num.to_i, user.to_i, sys.to_i, 0, idle.to_i]
8+
end
9+
end
10+
11+
def self.memory
12+
memstat = `echo ::memstat | mdb -k`
13+
vmstat = `vmstat -s`
14+
15+
Memory.new(
16+
`pagesize`.to_i, # pagesize
17+
# wired
18+
extract_solaris_mval(memstat, 'Kernel', 'Boot pages', 'ZFS File Data'),
19+
# active
20+
extract_solaris_mval(memstat, 'Exec and libs'),
21+
# inactive
22+
extract_solaris_mval(memstat, 'Page cache', 'Anon'),
23+
# free
24+
extract_solaris_mval(memstat, 'Free \(cachelist\)', 'Free \(freelist\)'),
25+
extract_solaris_val(vmstat, 'page ins'), # pageins
26+
extract_solaris_val(vmstat, 'page outs') # pageouts
27+
)
28+
end
29+
30+
def self.network_interfaces
31+
dlstat = `dlstat -u R`
32+
dlstat.shift # ignore header
33+
dlstat.map do |line|
34+
# LINK IPKTS RBYTES OPKTS OBYTES
35+
link, ipkts, rbytes, opkts, obytes = line.strip.split(/\s+/)
36+
NetworkInterface.new(link, rbytes, 0, 0, obytes, 0,
37+
NetworkInterface::ETHERNET_TYPE)
38+
end
39+
end
40+
41+
def self.extract_solaris_val(uvmexp, name)
42+
regexp = Regexp.new('(\d+)\s' + name)
43+
uvmexp.lines.grep(regexp) do |line|
44+
return $1.to_i
45+
end
46+
end
47+
48+
def self.extract_solaris_mval(memstat, *names)
49+
val = 0
50+
names.each do |name|
51+
regexp = Regexp.new(name + '\s+(\d+)')
52+
memstat.grep(regexp) do |line|
53+
val += $1.to_i
54+
end
55+
end
56+
val
57+
end
58+
end

0 commit comments

Comments
 (0)