Network Traffic Statistics script based on/proc

Source: Internet
Author: User
#! /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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.