9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/modules/bsd.rb', line 9
def get_stats
output = { :cpu => {} }
output[:load_avg] = `sysctl -n vm.loadavg`.gsub(/\{|\}/,"").strip.split(" ").collect{|i| i.strip.to_f.round(2)}
cpu = `sysctl -n kern.cp_time`.strip.split(" ").collect{|i| i.strip.to_i}
cpu_start = Hash[[:user, :nice, :system, :interupt, :idle].zip(cpu)]
sleep(0.01)
cpu = `sysctl -n kern.cp_time`.strip.split(" ").collect{|i| i.strip.to_i}
cpu_end = Hash[[:user, :nice, :system, :interupt, :idle].zip(cpu)]
cpu_end.each do |key, value|
output[:cpu][key] = value - cpu_start[key]
end
output[:memory] = {
:wired => `sysctl -n vm.stats.vm.v_wire_count`.to_i,
:active => `sysctl -n vm.stats.vm.v_active_count`.to_i,
:inactive => `sysctl -n vm.stats.vm.v_inactive_count`.to_i,
:used => 0, :free => `sysctl -n vm.stats.vm.v_free_count`.to_i
}
output
end
|