Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Tue Oct 03, 2023 4:18 pm


Internet Protocol, Transport Control Protocol, Network protocols, Routing, Routers, IP aliases, Routes, Ethernet

Author Message
admin
Post  Post subject: Linux script for interface network bandwidth monitoring  |  Posted: Mon Feb 09, 2015 7:05 pm
Site Admin

Joined: Mon Aug 03, 2009 8:43 am
Posts: 104

Offline
 

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

_________________
VPSie - SSD VPS servers in AMS-IX, LINX, DE-CIX
https://vpsie.com





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Linux script for interface network bandwidth monitoring"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. FreeBSD show network interface statistics

mandrei99

0

5645

Wed Sep 25, 2013 9:30 am

mandrei99 View the latest post

There are no new unread posts for this topic. Linux How to change hardware MAC address of an interface

debuser

1

3563

Tue Dec 06, 2011 6:26 am

Zettie49 View the latest post

There are no new unread posts for this topic. Linux list the outgoing interface for packets to a specific IP destination

mandrei99

0

3251

Mon Jul 22, 2013 10:17 am

mandrei99 View the latest post

There are no new unread posts for this topic. "OSPF not enabled on this interface" FreeBSD Quagga ospfd interface status

debuser

1

5479

Thu Apr 01, 2010 5:55 am

debuser View the latest post

There are no new unread posts for this topic. KVM: List MAC address table and interface that learned them.

mandrei99

0

4525

Sun Feb 01, 2015 6:26 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD list interface multicast group membership

mandrei99

0

4618

Tue Dec 03, 2013 9:02 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to accept IPv6 Router Advertisements on interface in FreeBSD

mandrei99

0

3757

Wed Apr 29, 2015 3:54 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD list the outgoing interface for packets to a specific IP destination

mandrei99

0

2905

Mon Jul 22, 2013 10:12 am

mandrei99 View the latest post

There are no new unread posts for this topic. FreeBSD + IPerf send multicast source traffic via specific interface

mandrei99

3

6184

Sat Apr 11, 2015 5:28 am

areeba View the latest post

There are no new unread posts for this topic. FreeBSD + IPERF sending IGMP v2 multicast group join / leave via specific interface

mandrei99

0

7202

Mon Jul 22, 2013 10:41 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 1 guest
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cronNews News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO