vnStat – Network Monitoring
I have been asked a variety of times “How can I monitor how much traffic I send and receive?”. The solution to this problem is simple, vnStat. “vnStat is a network traffic monitor for Linux that keeps a log of daily network traffic for the selected interface(s). vnstat isn’t a packet sniffer. The traffic information is analyzed from the /proc filesystem.” (vnstat, 2008).
The first step that we need to do is download the vnStat software. This can be downloaded from the vnStat website . Once you have downloaded the vnStat source package you can move the source file into the /usr/src/ directory and begin to decompress the archive as shown in Figure 1.
Server2:~ # mv vnstat-1.6.tar.gz /usr/src Server2:~ # cd /usr/src Server2:/usr/src # tar zvxf vnstat-1.6.tar.gz vnstat-1.6/ vnstat-1.6/FAQ vnstat-1.6/UPGRADE vnstat-1.6/src/ ... ...
Figure 1: Decompressing the vnStat archive.
Once you have decompressed the vnStat archive you will need to change into the vnStat directory and issue the make, make install and make clean command as shown in Figure 2.
Server2:/usr/src/vnstat-1.6 # make make -C src vnstat make: Entering directory `/usr/src/vnstat-1.6/src' gcc -O2 -c ifinfo.c ... Server2:/usr/src/vnstat-1.6 # make install Installing vnStat... Installing ppp/ip-up script ... Server2:/usr/src/vnstat-1.6 # make clean make -C src clean make: Entering directory `/usr/src/vnstat-1.6/src' ...
Figure 2: Compiling the vnstat software.
Once you have compiled the vnStat software you are almost finished. You will need to issue the vnstat -u -i eth0 command which will create a database which will store the network traffic statistics as shown in Figure 3.
Server2:~ # vnstat -u -i eth0 Error: Unable to read database "/var/lib/vnstat/eth0". -> A new database has been created.
Figure 3: Creating and updating the vnstat database.
Once you have issued the command shown in Figure 3 you have finished, the vnStat database will be updated every five minutes. If you are unhappy about that you can modify the vnStat cron file /etc/cron.d/vnstat.
The vnStat utility can display network statistics in a variety of ways. The simplest way is to issue the vnstat -q command which will query the vnStat database as shown in Figure 4.
Server2:~ # vnstat -q Database updated: Thu Jul 17 18:40:03 2008 eth0 received: 6.25 GB (99.7%) transmitted: 18.45 MB (0.3%) total: 6.27 GB rx | tx | total -----------------------+------------+----------- today 6.25 GB | 18.45 MB | 6.27 GB -----------------------+------------+----------- estimated 26.03 GB | 74 MB | 26.10 GB
Figure 4: Querying the vnstat database.
As you can see from Figure 4 network statistics have been gathered and presented in an easily readable format. If you would like to know what other qualifiers are supported by vnStat you can issue the vnstat –help command.
If you are experiencing any mysterious problems with vnStat, you can make sure you kernel is compatible by issuing the vnstat –testkernel command as shown in Figure 5.
Server2:~ # vnstat --testkernel This test will take about 60 seconds. [==============================] done. Detected boot time variation during test: 0 Maximum boot time variation set in config: 15 The current kernel doesn't seem to suffer from boot time variation problems. Everything is ok.
Figure 5: Checking the compatibility of vnstat.