实现原理:
[chengmo@localhost~]$cat/proc/net/dev
Inter-|Receive|Transmit
face|bytespacketserrsdropfifoframecompressedmulticast|bytespacketserrsdropfifocollscarriercompressed
lo:1068205690128894283900000010682056901288942839000000
eth0:915818443341438950000014554167642051130783435231517000000
proc/net/dev文件保存了网卡总流量信息,通过间隔一段间隔,将入网卡与出记录加起来。减去之前就得到实际速率。
程序代码:
复制代码