Skip to content

Commit

Permalink
use vmstat instead of /proc/stat for cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherdancev Evgeni committed May 19, 2015
1 parent bc3b4a5 commit df4cbea
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/im_mad/remotes/kvm-probes.d/kvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,15 @@ def print_info(name, value)
}

######
# for everything else, top & proc
#####

NETINTERFACE = "eth|bond|em|enp|p[0-9]+p[0-9]+"

stat = `cat /proc/stat`

stat.each_line do |line|
if /\Acpu (.*)\Z/.match(line)
stat_cpu = Regexp.last_match[1].to_s.split
stat_total_cpu = stat_cpu.inject(0) {|sum,s| sum.to_i+s.to_i}.to_i
$free_cpu = $total_cpu * stat_cpu[3].to_f / stat_total_cpu
$used_cpu = $total_cpu - $free_cpu
end
end
# CPU
######
vmstat = `vmstat 1 2`
$free_cpu = $total_cpu * ((vmstat.split("\n").to_a.last.split)[14].to_i)/100
$used_cpu = $total_cpu - $free_cpu

######
# MEMORY
######
memory = `cat /proc/meminfo`
meminfo = Hash.new()
memory.each_line do |line|
Expand All @@ -68,6 +61,11 @@ def print_info(name, value)
$used_memory = meminfo['MemTotal'] - meminfo['MemFree'] - meminfo['Buffers'] - meminfo['Cached']
$free_memory = $total_memory - $used_memory

######
# INTERFACE
######
NETINTERFACE = "eth|bond|em|enp|p[0-9]+p[0-9]+"

net_text=`cat /proc/net/dev`
exit(-1) if $?.exitstatus != 0

Expand Down

0 comments on commit df4cbea

Please sign in to comment.