Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides https://forum.ivorde.com/ |
|
Linux script for interface network bandwidth monitoring https://forum.ivorde.com/linux-script-for-interface-network-bandwidth-monitoring-t19764.html |
Page 1 of 1 |
Author: | admin [ Mon Feb 09, 2015 7:05 pm ] |
Post subject: | Linux script for interface network bandwidth monitoring |
This is a simple script that gets RX / TX values of an interface from /sys pseudo filesystem and calculate difference between current and old values displaying a bandwidth output for kilobytes per second. Code: #!/bin/bash
INT="1" # every INT seconds while true do RX1=`cat /sys/class/net/$1/statistics/rx_bytes` TX1=`cat /sys/class/net/$1/statistics/tx_bytes` sleep $INT RX2=`cat /sys/class/net/$1/statistics/rx_bytes` TX2=`cat /sys/class/net/$1/statistics/tx_bytes` TXBPS=`expr $TX2 - $TX1` RXBPS=`expr $RX2 - $RX1` TXKBPS=`expr $TXBPS / 1024` RXKBPS=`expr $RXBPS / 1024` echo "TX $1: $TXKBPS kb/s RX $1: $RXKBPS kb/s" done |
Page 1 of 1 | All times are UTC - 5 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |