通过读系统文件来统计系统吞吐数据
/sys/class/net/network-interface/statistics
root@Dev[09:41:51]$ ll /sys/class/net/eth0/statistics total 0 -r--r--r-- 1 root root 4096 Jun 29 14:59 collisions -r--r--r-- 1 root root 4096 Jun 29 14:59 multicast -r--r--r-- 1 root root 4096 Jun 29 14:47 rx_bytes -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_compressed -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_crc_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_dropped -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_fifo_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_frame_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_length_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_missed_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_nohandler -r--r--r-- 1 root root 4096 Jun 29 14:59 rx_over_errors -r--r--r-- 1 root root 4096 Jun 29 14:44 rx_packets -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_aborted_errors -r--r--r-- 1 root root 4096 Jun 29 14:47 tx_bytes -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_carrier_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_compressed -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_dropped -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_fifo_errors -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_heartbeat_errors -r--r--r-- 1 root root 4096 Jun 29 14:44 tx_packets -r--r--r-- 1 root root 4096 Jun 29 14:59 tx_window_errors root@Dev[09:48:12]$
统计收发包
#!/bin/bash
INTERVAL="1" # update interval in seconds
if [ -z "$1" ]; then
echo
echo usage: $0 [network-interface]
echo
echo e.g. $0 eth0
echo
echo shows packets-per-second
exit
fi
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_packets`
T1=`cat /sys/class/net/$1/statistics/tx_packets`
sleep $INTERVAL
R2=`cat /sys/class/net/$1/statistics/rx_packets`
T2=`cat /sys/class/net/$1/statistics/tx_packets`
TXPPS=`expr $T2 - $T1`
RXPPS=`expr $R2 - $R1`
echo "TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s"
done
统计带宽
#!/bin/bash
INTERVAL="1" # update interval in seconds
if [ -z "$1" ]; then
echo
echo usage: $0 [network-interface]
echo
echo e.g. $0 eth0
echo
exit
fi
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep $INTERVAL
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`
echo "TX $1: $TKBPS kB/s RX $1: $RKBPS kB/s"
done
作者:Standby — 一生热爱名山大川、草原沙漠,还有我们小郭宝贝!
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号