Novell Cool Solutions

Network Traffic Monitoring


July 25, 2008 11:30 am





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 [1]. 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

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[1]: 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[1]: 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
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


           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.



1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5 (1 votes, average: 5.00 out of 5)
You need to be a registered member to rate this post.

Categories: Uncategorized


Disclaimer: This content is not supported by Novell. It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test it thoroughly before using it in a production environment.