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
    
  • 相关阅读:
    C++对象模型
    Session、Application、Cache
    JavaScript事件的几个细节
    algorithm(算法)
    【REST WCF】30分钟理论到实践
    实践Scrum
    调试PostSharp DEMO 遇到的问题
    6.8 按字符串中的部分内容排序
    QObject就有eventFilter,功能很强(随心所欲的进行处理,比如用来QLineEdit分词)
    QPainter就是手里的作图工具,只需要三洋东西:笔(颜色,宽度,样式),字体(写字),刷子(大面积作画),这里有三个典型例子
  • 原文地址:https://www.cnblogs.com/standby/p/13212078.html
Copyright © 2011-2022 走看看