How to Monitor Network Traffic using vnStati and vnStat

To Install vnStati and vnStat to Monitor Network Traffic on Debian 8.3

In this article we are going to learn how to install vnStati and vnStat to keep log of to monitor traffic. The latest version of vnStat is vnStat 1.13.

Features

  • After the system reboots, the Statistics remains available
  • Multiple output options
  • Generate png graphic output
  • Very light, consumes lite portion of system resources
  • Uses JSON for output
  • Monitor multiple network interfaces at same time
  • Sort the data by month, week, hour and day
  • Low CPU usage
  • Hide legend use -nl /
  • To alternative date/time text location use &ndash altdate
  • To customize the text in the image header use &ndash headertext
  • Interface bandwidth will reduce automatically

To Install vnStat and vnStati Network Monitoring Tools

Execute the following commands to install vnStat and vnStati Network Monitoring Tools.

root@linuxhelp:~# apt-get install vnstat vnstati
Reading package lists... Done
Building dependency tree       
Reading state information... Done
.
.
.
Processing triggers for systemd (215-17+deb8u3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up vnstat (1.12-2) ...
Setting up vnstati (1.12-2) ...
Processing triggers for systemd (215-17+deb8u3) ...

Create new database for network interface to monitor, after installation completed. Create vnstat directory into /var/lib/ directory.

root@linuxhelp:~# mkdir /var/lib/vnstat

Then run following command to create new database for present active network interface.

root@linuxhelp:~# vnstat --create -i eth0
Creating database for interface " eth0" ...
Info: ->  A new database has been created.

Restart the vnStat daemon, if it is currently running in order to start monitoring " eth0" .

root@linuxhelp:~# service vnstat restart

To update the stats in the database

Execute the below command to update the stats in the database.

root@linuxhelp:~# vnstat
Database updated: Tue Jun  7 13:32:55 2016

   eth0 since 07/06/16

          rx:  87.92 MiB      tx:  3.51 MiB      total:  91.43 MiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Jun ' 16     87.92 MiB |    3.51 MiB |   91.43 MiB |    1.32 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated       397 MiB |      13 MiB |     410 MiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
         today     87.92 MiB |    3.51 MiB |   91.43 MiB |   15.36 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated       154 MiB |       5 MiB |     159 MiB |

Using -h option, can check the hourly stats.

root@linuxhelp:~# vnstat -h
 eth0                                                                     13:37 
  ^                                                                    r        
  |                                                                 r  r  r     
  |                                                                 r  r  r     
  |                                                                 r  r  r     
  |                                                                 r  r  r     
  |                                                                 r  r  r     
  |                                                                 r  r  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     29,959      1,199
20          0          0    04          0          0    12     30,054      1,200
21          0          0    05          0          0    13     30,022      1,200

Use -d option for daily stats.

root@linuxhelp:~# vnstat -d

 eth0  /  daily

         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      07/06/16     87.92 MiB |    3.51 MiB |   91.44 MiB |   15.26 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated       153 MiB |       5 MiB |     158 MiB |

Use -w option for weekly stats.

root@linuxhelp:~# vnstat -w

 eth0  /  weekly

                      rx      |     tx      |    total    |   avg. rate
   ---------------------------+-------------+-------------+---------------
    last 7 days     87.93 MiB |    3.51 MiB |   91.45 MiB |    1.32 kbit/s
   current week     87.93 MiB |    3.51 MiB |   91.45 MiB |    5.52 kbit/s
   ---------------------------+-------------+-------------+---------------
      estimated       395 MiB |      13 MiB |     408 MiB |

To use vnStati tool to generate .png images.

root@linuxhelp:~# vnstati -s -i eth0 -o /root/Desktop/summary.png

root@linuxhelp:~# vnstati -h -i eth0 -o /root/Desktop/summary1.png

Use vnstat --help option to view all options in vnstat.

root@linuxhelp:~# vnstat --help
 vnStat 1.12 by Teemu Toivola 

         -q,  --query          query database
         -h,  --hours          show hours
         -d,  --days           show days
         -m,  --months         show months
         -w,  --weeks          show weeks
         -t,  --top10          show top10
         -s,  --short          use short output
         -u,  --update         update database
         -i,  --iface          select interface (default: eth0)
         -?,  --help           short help
         -v,  --version        show version
         -tr, --traffic        calculate traffic
         -ru, --rateunit       swap configured rate unit
         -l,  --live           show transfer rate in real time

See also " --longhelp" for complete options list and " man vnstat" . You can find more information about vnStat in the man page of tool.

FAQ
Q
How to install vnstati and vnstat package in ubuntu?
A
use the following command to install vnstat and vnstati
# apt-get install vnstat vnstati
Q
what are all the features of monitoring network traffic?
A
After the system reboots, the Statistics remains available
Multiple output options
Generate png graphic output
Very light, consumes lite portion of system resources
Uses JSON for output
Monitor multiple network interfaces at same time
Sort the data by month, week, hour and day
Q
where to download latest version of vnstat?
A
refer the following link to download the latest version of vnstat
https://humdi.net/vnstat/vnstat-1.18.tar.gz
Q
Where to refer the documentation for vnstat command?
A
use the following link for reference,
https://humdi.net/vnstat/
Q
any other command like vnstat available in linux?
A
you can try
nload
iftop
iptraf
bmon