Real-time server network speed monitoring (shell script)

Source: Internet
Author: User

Usage:

#> Moniotr. Sh eth0 1

#! /Bin/bash

# Test network width
# The first parameter indicates the Real-Time refresh time after the NIC name. 1 indicates 1 second.

Function usage
{
Echo "Usage: $0"
Echo "e.g. $0 eth0 2"
Exit 65
}
If [$ #-lt 2]; then
Usage
Fi
Typeset in in_old dif_in
Typeset out out_old dif_out
Typeset Timer
Typeset ETH

Eth = $1
Timer = $2

in_old = $ (CAT/proc/NET/dev | grep $ ETH | sed-e "s /\(. *\)\:\(. * \)/\ 2/g "| awk '{print $1 }')
out_old = $ (CAT/proc/NET/dev | grep $ ETH | sed-e "s /\(. *\)\:\(. * \)/\ 2/g "| awk '{print $9 }')
while true
DO
sleep $ {timer}
In =$ (CAT/proc/NET/dev | grep $ ETH | sed-e" S /\(. *\)\:\(. * \)/\ 2/g "| awk '{print $1 }')
out = $ (CAT/proc/NET/dev | grep $ ETH | sed-e "s /\(. *\)\:\(. * \)/\ 2/g "| awk '{print $9}')
dif_in = $ (in-in_old)/timer ))
dif_out = $ (out-out_old)/timer)
echo "in: $ {dif_in} byte/s out: $ ($ {dif_out}/1024) kb/s: $ {dif_out} byte/s "
in_old =$ {In}
out_old =$ {out}
done
exit 0

Related Article

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.