How To Use VNSTAT To Monitor Bandwidth Usage.

There are so many tools to monitor network such as MRTG, now I am going to explain such tool which monitors bandwidth for a system, ie vnstat(view network statistics). Its very much easy to install and configure.

This tool can give you full details about how much bandwidth used on the basics of,

Per month.

Per week.

Per day.

Per hour.

Per second.

Even we can see live traffic. This is awesome tool .

So all the tools will not only have advantages but also disadvantages, here are they:
1)Can not monitor multiple interfaces at a time.
2)Can not monitor remote host.
3)Can not monitor per host statistics(which is verymuch useful to find the network hogger, if you want per host bandwidth analyser then use iptables counters for it).

Before configuring vnstat, one thing we have to keep in mind that vnstat is a aggregating tool which is required to run at regular intervals to monitor network bandwidth. So by default when we install vnstat a cron job is created at /etc/cron.d folder.

Step1 : installing vnstat

#rpm –ivh vnstat-1.6-2.fc9.i386.rpm

Step2 : Configuring vnstat.
As I mention earlier that vnstat is an aggregate tool so it should run background by using crontab, So first edit the cron job

Vi /etc/cron.d/vnstat
*/5 * * * * vnstat /usr/sbin/vnstat.cron
Add the above line to the file, then save it and exit.

Step3 : Specifying which interface to monitor

#vnstat –I interfacename

Example :
[root@test ~]# vnstat -i eth0
Error :
Unable to read database "/var/lib/vnstat/eth0".
eth0: Not enough data available yet.

Don’t worry about error intitially it will show error because it’s the first time you are executing that command, so it has to create DB.

Step4 : Monitoring bandwidth with different intervals

Type1 : For live traffic

#vmstat –l
-l is nothing but live
Example:
[root@test ~]# vnstat -l
Monitoring eth0... (press CTRL-C to stop)
rx: 8.32 kB/s 30 p/s tx: 0.19 kB/s 0 p/s
eth0 / traffic statistics
rx tx
--------------------------------------+----------------------------------------
bytes 206 kB 4 kB
--------------------------------------+----------------------------------------
max 11.19 kB/s 0.24 kB/s
average 7.96 kB/s 0.19 kB/s
min 6.35 kB/s 0.11 kB/s
--------------------------------------+----------------------------------------
packets 695 16
--------------------------------------+----------------------------------------
max 61 p/s 2 p/s
average 26 p/s 0 p/s
min 9 p/s 0 p/s
--------------------------------------+----------------------------------------
time 26 seconds

Type2 :For monitoring traffic per second

#vmstat –tr 5
This command will monitor bandwidth for 5 seconds and give you the output.

Type3 : For hourly

#vmstat –h

Example :
[root@test ~]# vnstat -h
eth0 21:00
^ r
r
r
r
r
r
r
r
r
r
-+--------------------------------------------------------------------------->
22 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
h rx (kB) tx (kB) h rx (kB) tx (kB) h rx (kB) tx (kB)
22 0 0 06 0 0 14 0 0
23 0 0 07 0 0 15 0 0
00 0 0 08 0 0 16 0 0
01 0 0 09 0 0 17 0 0
02 0 0 10 0 0 18 0 0
03 0 0 11 0 0 19 0 0
04 0 0 12 0 0 20 12,614 41
05 0 0 13 0 0 21 0 0

Type4:For dialy

#vmstat –d
Example :
[root@test ~]# vnstat -d
eth0 / daily
day rx tx total
------------------------+-------------+----------------------------------------
09.09. 12.32 MB 41 kB 12.36 MB %%%%%%%%%%%%%%%%%%%%%%%%%
------------------------+-------------+----------------------------------------
estimated -- -- --

Type5 : For weekly

#vmstat –w

Example :
[root@test ~]# vnstat -w
eth0 / weekly
rx tx total
----------------------------+---------------+--------------
last 7 days 12.32 MB 41 kB 12.36 MB
current week 12.32 MB 41 kB 12.36 MB
----------------------------+---------------+--------------
estimated -- -- --

Type6 : For monthly
#vmstat –m
Example :
[root@test ~]# vnstat -m
eth0 / monthly
month rx tx total
-------------------------+--------------+--------------------------------------
Sep '09 12.32 MB 41 kB 12.36 MB %%%%%%%%%%%%%%%%%%%%%%
-------------------------+--------------+--------------------------------------

No comments:

Post a Comment