Linux menu

Wednesday, September 17, 2014

Monitor Network Traffic and Watch Bandwidth Usage using vnStat In Linux

vnstat is a console-based network traffic monitor for Linux that keeps a daily log of network traffic for a specific device. Information is simply taken from /proc every 5 minutes via vnstatd daemon and saved to /var/lib/vnstat. Unlike other network monitor tools, it keeps an accurate and numerical account of all network traffic, this is very useful if you have to watch bandwidth usage.

Install vnStat

Installing vnStat it’s simple because it’s available in the repository of most Linux distributions like Debian, Ubuntu, Fedora or CentOS. On Ubuntu Linux you can easily install it using the apt-get install command as follows:
$ sudo apt-get install vnstat
vnstat install
This will automatically install vnStat and any dependencies needed.

How to Use vnStat

Using this utility is simple, first invoke it without any argument like this:
$ vnstat
If you get an output like this:
vnstat no data
It means that the daemon didn’t have enough time to collect data, you should give it about 15 minutes after installation to collect data so it can display useful information. After the data is collected you will start getting an output like this:
vnstat
It the table rx stands for received data, tx for transmitted data, total for both received and transmitted data. You also get a weekly and daily report.
vnStat has quite a few options you can use as follow:
-h, show data grouped by hours
-d, show data grouped by days
-m, show data grouped by months
-w, show data grouped by weeks
-t, show data grouped by top10
The output looks like this:
vnstat options
Another options is -u, it will update the database right away, you will need root to run that flag since it requires to write the database file.
You can also use the -l flag to view the traffic in real time like this:
vnstat live
This will show you the current receiving and transmitting rates and packets per second rates in real time. You can select a particular interface with the -i option.
vnStat is a nice utility to have around if bandwidth usage is a concern for you, it’s designed to be lightweight, basic and efficient. You can find more information about it on the vnStat webpage
- See more at: http://linoxide.com/monitoring-2/vnstat-network-traffic-monitor/#sthash.KOcsRpuw.dpuf

No comments: