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
    
  • 相关阅读:
    从零开始学安全(四十四)●TCP三次握手四次挥手
    从零开始学安全(四十三)●Wireshark分析ICMP(IP)协议
    从零开始学安全(四十二)●利用Wireshark分析ARP协议数据包
    从零开始学安全(四十一)●初识Wireshark
    从零开始学安全(四十)●上传文件MIME类型绕过漏洞防御
    从零开始学安全(三十九)●FCK编辑器解析漏洞
    《Web安全深度剖析》
    从零开始学安全(三十八)●cobaltstrike生成木马抓肉鸡
    从零开始学安全(三十七)●VM汇编环境搭建
    C#继承练习2
  • 原文地址:https://www.cnblogs.com/standby/p/13212078.html
Copyright © 2011-2022 走看看