#!/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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。