Monitoring Network Traffic or Bandwidth Usage is an important task in an organisational structure or even for developers. It is sometimes required to monitor traffic on various systems which share the internet bandwidth. There might be situations where network statistics are required for decision making in the networking areas or use the logged information on the network traffic for analysis tasks.
vnStat and vnStati are command line utilities which are very useful tools that help a user to monitor, log and view network statistics over various time periods. It provides summaries on various network interfaces, may it be wired like “eth0” or wireless like “wlan0”. It allows the user to view hourly, daily, monthly statistics in the form of a detailed table or a command line statistical view. To store the results in a graphical format, we can use the vnStati to obtain and provide visual display of statistics in the form of graphs and store them in the form of images for later use.
This post deals with the procedure to install and use vnStat and vnStati. It also details the options and usage methods required to view and store the type of information you want. vnStat does most of the logging and updating , where as vnStati is used to provide a graphical display of the statistics.
2 Installing vnStat and vnStati
To install the two command line tools use the following two commands:
sudo apt-get install vnstat
sudo apt-get install vnstati
Enter your password and wait for it to install. Once done, test if it has installed correctly by typing “vnstat” and “vnstati” in the terminal. There shouldn’t be any error displayed saying, “vnstat not found” or “vnstati not found”.
3 vnStat setup and running
Once the installation is complete, vnStat has to be setup or configured as it does not start on its own. vnStat has to be told explicitly which interfaces have to be monitored. We then start the vnStat daemon called “vnstatd”, which starts vnStat and monitors for as long as it is not stopped explicitly.
The first thing to do here is tell vnStat the network interfaces to monitor. Here we look at a wired interface “eth0” and a wireless interface “wlan0”. Type the following commands in the terminal.
vnstat -u -i eth0
This above command activates monitoring that interface. The first time you run this command on any interface you will get an error saying ‘Unable to read database “/var/lib/vnstat/eth0” ‘. Please ignore this. Refer to the image below.
Similar to above we also set the wireless network interface using the command:
vnstat -u -i wlan0
To view all the network interfaces available in your system, use the command:
Once you know all the interfaces that you want to be monitored, use the command above with that interface name to monitor the traffic on it. Below is an image of the available interfaces in my system, Yours might be similar.
Once the above steps are complete, we can now start the vnStat daemon. To do this, we use the following command:
sudo /etc/init.d/vnstat start
You can check to see of the daemon process is running, by using the following command and the image of the output is shown below that:
ps -f | grep vnst
To view my full post, visit here.