Monitoring bandwidth of the network, gateway and servers are one of important day to day activity of System Administrator. Bandwidth monitoring can help us to monitor the activities on network. We can easily monitor the users bandwidth usage and control their activities. Monitoring help us keep aware of the each day activities on our network, thus help to prevent harmful activities inside the network eg: torrent download.
Their are many techniques to control and monitor the bandwidth usage. Here i like to explain a simple monitoring tool called “Vnstat”. Vnstat help us to monitor the bandwidth usage on each network interfaces. Operating and monitoring using vnstat is simple. We can also view the usage using web interface.
Vnstat tool can able to calculate the total bandwidth usage on each interface.
Configure Vnstat On Linux
1. Download Vnstat tar.gz.
# cd /donwloadlocation # wget http://humdi.net/vnstat/vnstat-1.9.tar.gz
**Vnstat is also available via yum installation using rpmforge repo
2. Extract downloaded vnstat package.
# tar -xvzf vnstat-1.9.tar.gz# cd vnstat-1.9/
3. Compiling the binaries.
# make all
*Required extra packages are usually named libgd2 and libgd2-dev (or libgd2-noxpm and libgd2-noxpm-dev in Debian/Ubuntu, xpm version can also be used)
4. Installing vnstat.
Login as root and run the following command,
# make install
5. Test Kernel compatibility.
# vnstat –testkernel
If the kernel is not compatible we need to upgrade the kernel.
6. Check the interface availability.
# vnstat –iflist
eg: Available interfaces: lo eth0 sit0
7. Create new databases for the monitoring interface.
# vnstat -u -i eth0
Repeat that for every other interface you wish to use.
eg: # vnstat -u -i eth0
Error: Unable to read database “/var/lib/vnstat/eth0″.
Info: -> A new database has been created.
**Set write permission for interface database files inside “/var/lib/vnstat/”
8. Run Vnstat via cron.
Edit the crontab and add the following line,
# crontab -e
Add the line into crontab
*/5 * * * * /usr/bin/vnstat -u
The script will update vnstat database in every five minutes. We can also define the same vnstat cron on /etc/cron.d/ folder. Only one cron definition is required.
# vi /etc/cron.d/vnstat
Add the same line
*/5 * * * * /usr/bin/vnstat -u
9. Reload crond
# /etc/init.d/crond reload
10. View the Bandwidth usage.
Run the command.
# vnstat
Configure Web Interface for Vnstat
1. Download the vnstat php frontend
# cd /tmp # wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.tar.gz
2. Extract the package.
# tar -xvzf vnstat_php_frontend-1.4.tar.gz
3. Move the package to html doc root.
# mv vnstat_php_frontend-1.4 /var/www/html/vnstat
* Apache must configure to handle php request.
4. Edit config.php
Specify the network interface,
$iface_list = array(‘eth0′, ‘eth1′);
Specify interface function on the following line,
$iface_title[‘eth0′] = ‘Internal';
$iface_title[‘eth1′] = ‘Internet';
Comment the line,
//$iface_title[‘sixxs’] = ‘SixXS IPv6′;
Specify the vnstat command. Use which command to locate the path.
# which vnstat
$vnstat_bin = ‘/usr/bin/vnstat';
Now open browser and browser the url eg: http://bdgw2.talk2melbin.com. Secure the root directory using .htaccess password protection.
Cheers!
Melbin Mathew
www.talk2melbin.com
Melbin Mathew
Latest posts by Melbin Mathew (see all)
- VMware virtual IDE to virtual SCSI hard disk conversion steps – Windows XP - August 6, 2015
- Stop Error “CRITICAL_STRUCTURE_CORRUPTION - August 5, 2015
- Error installing Windows server role and feature required for the Exchange 2010 - December 3, 2013