#!/usr/bin/ruby
cpunum = ` cat /proc/cpuinfo |grep processor|wc -l`.to_i
before = {}
while true
file = File.readlines('/proc/interrupts')
puts "ifname cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 cpu8 cpu9 cpu10 cpu11 "
file.each do |i|
if i.include?("TxRx")
lines = i.split(" ")
print "#{lines[-1]}: #{lines[1].to_i - before["#{lines[-1]}-1"].to_i} \t"
print "#{lines[2].to_i - before["#{lines[-1]}-2"].to_i} \t"
print "#{lines[3].to_i - before["#{lines[-1]}-3"].to_i} \t"
print "#{lines[4].to_i - before["#{lines[-1]}-4"].to_i} \t"
print "#{lines[5].to_i - before["#{lines[-1]}-5"].to_i} \t"
print "#{lines[6].to_i - before["#{lines[-1]}-6"].to_i} \t"
print "#{lines[7].to_i - before["#{lines[-1]}-7"].to_i} \t"
if cpunum == 8
puts "#{lines[8].to_i - before["#{lines[-1]}-8"].to_i} \t"
elsif cpunum == 12
print "#{lines[8].to_i - before["#{lines[-1]}-8"].to_i} \t"
print "#{lines[9].to_i - before["#{lines[-1]}-9"].to_i} \t"
print "#{lines[10].to_i - before["#{lines[-1]}-10"].to_i} \t"
print "#{lines[11].to_i - before["#{lines[-1]}-11"].to_i} \t"
puts "#{lines[12].to_i - before["#{lines[-1]}-12"].to_i}"
end
before["#{lines[-1]}-1"] = lines[1]
before["#{lines[-1]}-2"] = lines[2]
before["#{lines[-1]}-3"] = lines[3]
before["#{lines[-1]}-4"] = lines[4]
before["#{lines[-1]}-5"] = lines[5]
before["#{lines[-1]}-6"] = lines[6]
before["#{lines[-1]}-7"] = lines[7]
before["#{lines[-1]}-8"] = lines[8]
if cpunum == 12
before["#{lines[-1]}-9"] = lines[9]
before["#{lines[-1]}-10"] = lines[10]
before["#{lines[-1]}-11"] = lines[11]
before["#{lines[-1]}-12"] = lines[12]
end
end
end
puts
sleep 2
end
分享文章:查看网卡中断绑定情况的脚本
浏览路径:
http://bzwzjz.com/article/gdjsgj.html