How to Monitor Network Bandwidth with vnstat
There are many tools available to monitor our network bandwidth usage at a particular date and time. Those tools will collect and send the bandwidth usage to system or network admins to find out what’s going on in there network infrastructure. We have already shown you how to monitor network bandwidth using iftop tool. Well, today i have come back with a tool called vnstat.
vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnstat won’t actually be sniffing any traffic and also ensures light use of system resources. However, in Linux at least a 2.2 series kernel is required.
It is very simple to install and use. It can monitor multiple network interfaces at the same time. It will display the output summary in hourly, daily, weekly and as well as monthly basis. And it can be used without root permissions.
Install vnstat
On Debian/Ubuntu:
sk@sk:~$ sudo apt-get install vnstat
On RHEL/CentOS:
vnstat will not be found in Official repositories, so add EPEL repository to install vnstat:
[root@server ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Install vnstat with following command:
[root@server ~]# yum install vnstat -y
Usage
To view all network interfaces statistics, enter the following command:
sk@sk:~$ vnstat
This shows network bandwidth usage of all network interfaces:
rx / tx / total / estimated eth1: Jul '13 4.77 MiB / 204 KiB / 4.97 MiB / 0 KiB today 4.77 MiB / 204 KiB / 4.97 MiB / -- wlan0: Not enough data available yet. eth0: Not enough data available yet.
To view a particular interface bandwidth usage, enter the command:
sk@sk:~$ vnstat -i eth1
The above command will display the bandwidth usage of eth1:
Database updated: Thu Jul 4 13:26:10 2013 eth1 since 07/04/13 rx: 4.82 MiB tx: 249 KiB total: 5.07 MiB monthly rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- Jul '13 4.82 MiB | 249 KiB | 5.07 MiB | 0.13 kbit/s ------------------------+-------------+-------------+--------------- estimated -- | -- | -- | daily rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- today 4.82 MiB | 249 KiB | 5.07 MiB | 0.86 kbit/s ------------------------+-------------+-------------+--------------- estimated -- | -- | -- |
To view the hourly usage, use the parameter “-h” without quotes:
sk@sk:~$ vnstat -i eth1 -h eth1 13:31 ^ r | r | r | r | r | r | r | r | r | r -+---------------------------------------------------------------------------> | 14 15 16 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 h rx (KiB) tx (KiB) h rx (KiB) tx (KiB) h rx (KiB) tx (KiB) 14 0 0 22 0 0 06 0 0 15 0 0 23 0 0 07 0 0 16 0 0 00 0 0 08 0 0 17 0 0 01 0 0 09 0 0 18 0 0 02 0 0 10 0 0 19 0 0 03 0 0 11 0 0 20 0 0 04 0 0 12 0 0 21 0 0 05 0 0 13 4964 290
To view daily usage, use the parameter “-d”:
sk@sk:~$ vnstat -i eth1 -d eth1 / daily day rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- 07/04/13 4.82 MiB | 249 KiB | 5.07 MiB | 0.86 kbit/s ------------------------+-------------+-------------+--------------- estimated -- | -- | -- |
To view weekly usage, use the parameter “-w”:
sk@sk:~$ vnstat -i eth1 -w eth1 / weekly rx | tx | total | avg. rate ---------------------------+-------------+-------------+--------------- last 7 days 4.85 MiB | 290 KiB | 5.13 MiB | 0.07 kbit/s current week 4.85 MiB | 290 KiB | 5.13 MiB | 0.14 kbit/s ---------------------------+-------------+-------------+--------------- estimated -- | -- | -- |
And to view monthly usage, use “-m”:
sk@sk:~$ vnstat -i eth1 -m eth1 / monthly month rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- Jul '13 4.85 MiB | 290 KiB | 5.13 MiB | 0.14 kbit/s ------------------------+-------------+-------------+--------------- estimated -- | -- | -- |
To see top ten network bandwidth usage of eth1:
sk@sk:~$ vnstat -i eth1 -t
To view the bandwidth usage of 5 seconds, enter the following command:
sk@sk:~$ vnstat -i eth1 -tr
To view the usage of 10 seconds, enter the following command:
sk@sk:~$ vnstat -i eth1 -tr 10
Finally to see the real live bandwidth usage of eth1:
sk@sk:~$ vnstat -i eth1 -l
This command will collect the network bandwidth usage of eth1. You can stop the process by pressing CTRL+C at any time.
Sample Output:
Monitoring eth1... (press CTRL-C to stop) rx: 0 kbit/s 0 p/s tx: 0 kbit/s 0 p/s rx: 0 kbit/s 0 p/s tx: 0 kbit/s 0 p/s^C eth1 / traffic statistics rx | tx --------------------------------------+------------------ bytes 17.96 MiB | 4.48 MiB --------------------------------------+------------------ max 3.78 Mbit/s | 420 kbit/s average 31.62 kbit/s | 7.90 kbit/s min 0 kbit/s | 0 kbit/s --------------------------------------+------------------ packets 22511 | 21780 --------------------------------------+------------------ max 336 p/s | 206 p/s average 4 p/s | 4 p/s min 0 p/s | 0 p/s --------------------------------------+------------------ time 77.55 minutes
Hope you have a basic idea about vnstat. You may wish to view graphs in cool graphical mode, well then check our article about vnStat PHP frontend tool.
Happy Monitoring!
Source:https://www.unixmen.com/how-to-monitor-network-bandwidth-with-vnstat/