Skip to content

Commit b45ce58

Browse files
author
Vincent Landgraf
committed
closes #12 use native pagesize and sysctl for cpu
1 parent d78d0d0 commit b45ce58

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

lib/vmstat/netopenbsd.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module Vmstat
22
def self.cpu
3-
vmstat = `vmstat 1 1`.lines[2].chomp.split(/\s+/)
4-
[Cpu.new(0, vmstat[-3].to_i, vmstat[-2].to_i, 0, vmstat[-1].to_i)]
3+
cptime = `sysctl kern.cp_time`.split(/=/).last
4+
user, nice, sys, irq, idle = cptime.split(/,/).map(&:to_i)
5+
[Cpu.new(0, user, sys + irq, nice, idle)]
56
end
67

78
def self.memory
89
uvmexp = `vmstat -s`
910

1011
Memory.new(
1112
# pagesize call is not used to avoid double shell out
12-
pagesize(uvmexp), # pagesize
13+
pagesize, # pagesize
1314
extract_uvm_val(uvmexp, 'pages managed'), # wired
1415
extract_uvm_val(uvmexp, 'pages active'), # active
1516
extract_uvm_val(uvmexp, 'pages inactive'), # inactive
@@ -19,11 +20,6 @@ def self.memory
1920
)
2021
end
2122

22-
def self.pagesize(uvmexp)
23-
uvmexp ||= `vmstat -s`
24-
extract_uvm_val(uvmexp, 'bytes per page')
25-
end
26-
2723
def self.network_interfaces
2824
bytes = `netstat -ibq`.lines.grep(/<Link>/) # bytes
2925
pkgs = `netstat -iqd`.lines.grep(/<Link>/) # packages

0 commit comments

Comments
 (0)