#! /Bin/sh # The following two parameters can be modified as needed: ethxname = eth0
# Nic name statfreq = 2 # statistical interval, in seconds. It is recommended to be a multiple of 2 or 2 # The following parameters, do not modify influx_kbps = 0outflux_kbps = 0influx_mbps = 0outflux_mbps = 0unsigned_long_max = 4294967295 # handle overflow ethname = 'cat
/Proc/NET/dev| Grep $ ethxname | awk-F "[:] +" '{printf ("% s", $2);} ''if test" $ ethxname "! = "$ Ethname"; thenecho "Please set ethxname first before running" exitfiinflux1_byte = 'cat/proc/NET/dev | grep $ ethxname | awk-F "[:] + "'{printf (" % d ", $3 );} ''outflux1 _ byte = 'cat/proc/NET/dev | grep $ ethxname | awk-F "[:] +" '{printf ("% d ", $11);} ''while Test 2-GT 1; dosleep $ statfreqinflux2_byte = 'cat/proc/NET/dev | grep $ ethxname | awk-F "[:] + "'{printf (" % d ", $3 );} ''outflux2 _ byte = 'cat/proc/NET/dev | grep $ ethxname | awk-F "[:] +" '{printf ("% d ", $11);} ''dd = 'date + '% Y-% m-% d/% H: % m: % s' if test $ influx2_byte-ge $ influx1_byte; thenlet influx_byte = $ influx2_byte-$ export influx_byte = $ unsigned_long_max-$ export influx_byte = $ influx_byte + $ export test $ outflux2_byte-ge $ outfluxw.byte; thenlet response = $ response-$ response outflux_byte = $ outflux_byte + $ response = $ response/$ statfreqlet outflux_byte = $ outflux_byte/$ statfreq # To bpslet response = $ response * 8let response = $ outflux_byte * 8 # To kbpslet response = $ response/1024let outflux_kbps = $ response/1024 # To mbpslet influx_mbps = $ response/1024let outflux_mbps = $ outflux_kbps/ 1024 # output column description: statistical time, input traffic (unit: Kbps), input traffic (mbps), output traffic (Kbps), output traffic (mbps) echo "$ DD, $ {influx_kbps} kbps, $ {influx_mbps} Mbps, $ {outflux_kbps} kbps, $ {outflux_mbps} Mbps "Let influx1_byte = influx2_bytelet outflux1_byte = outflux2_bytedone