There are a lot of network monitoring tool in the internet. The most popular one may be Multi Router Traffic Graph or known as MRTG. To access MRTG, we need to install a web server. If you don’t want to install a web server, you may want to use vnstat as an MRTG alternative. Vnstat is run in console mode.
Let’s start to know more about vnstat.
What is 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. -- Reference : vnstat website
Vnstat is available in source code file. The latest version is version 1.11 which can be download it from its download page. Since vnstat is available only in source code form, the we need to compile it first.
On Redhat / CentOS based you can do this steps.
Extract the file
$ tar zxfv vnstat-1.11.tar.gz
$ cd vnstat-1.11
You may need root privileges for it
# make install
Running vnstat at the first time
By default vnstat is installed in /usr folder. Then you will found vnstat binary file in /usr/bin/vnstat
For first time, you will need to create a database for it. To make a new database, use the command below. You may need a root privilege to run the command.
Vnstat still not find any database for it. But as you see at the screenshot, vnstat tell you how many interfaces that available. To double-check what interface that you want to monitor, run :
From the screenshot above we found eth1 is active. To monitor it, run this command :
$ /usr/bin/vnstat -u -i eth1
Don’t worry about the error above. It is normal for the first time. To check it does it running well or not, run this command :
$ /usr/bin/vnstat -l -i eth1
Here’s the sample output :
More detail with vnstat
Here’s some parameter that could be useful in daily operation.
Show hours based traffic
$ /usr/bin/vnstat --hours
Show days based traffic
$ /usr/bin/vnstat --days
Show weeks based traffic
$ /usr/bin/vnstat --weeks
Show months based traffic
$ /usr/bin/vnstat --months
Show Top 10 traffic
$ /usr/bin/vnstat --top10
$ /usr/bin/vnstat -tr
Show transfer rate in real time
$ /usr/bin/vnstat -l
I found it useful for daily operation. The advantage of vnstat there is no daemon service is running in the backgroud. Vnstat use cronjob to run periodically that make makes vnstat very light. You can also control everything via console mode. Vnstat also give you a clear information about megabtyes that you have send / receive in many format such as hours, days, week and month.
Please visit vnstat website to look more details or type man vnstat on your console.