zoukankan      html  css  js  c++  java
  • 通过读系统文件来统计系统吞吐数据

    摘自这里

    /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
    
  • 相关阅读:
    document.getElementById IE bug
    Add Event
    start silverlight
    【转】MSDN magzine JavaScript使用面向对象的技术创建高级 Web 应用程序
    文本编辑工具Vim
    《JavaScript DOM编程艺术》附录(dom方法和属性)
    js variable undefined
    good tools 调试好帮手
    my pretty code
    万级访问网站前期的技术准备(下)
  • 原文地址:https://www.cnblogs.com/standby/p/13212078.html
Copyright © 2011-2022 走看看