当前位置 博文首页 > 文章内容

    通过读系统文件来统计系统吞吐数据

    作者: 栏目:未分类 时间:2020-06-30 10:04:36

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    摘自这里

    /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