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 :

[[email protected]test ~]# vnstati eth0

Error :

Unable to rea
d 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

#vnstat –l

-l is nothing but live

Example:

[[email protected] ~]# 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

rxtx

————————————–+—————————————-

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

#vnstattr 5

This command will monitor bandwidth for 5 seconds and give you the output.

Type3 : For hourly

#vnstat –h

Example :

[[email protected] ~]# 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

hrx (kB) tx (kB) h rx (kB) tx (kB) h rx (kB) tx (kB)

22 0 06 0 14 0

23 0 07 0 15 0

00 0 08 0 16 0

01 0 09 0 17 0

02 0 10 0 18 0

03 0 11 0 19 0

04 0 12 0 20 12,614 41

05 0 13 0 21 0

 
Type4:For dialy<
/span>

#vnstat –d

Example :

[[email protected] ~]# vnstat -d

eth0 / daily

dayrxtx total

————————+————-+—————————————-

09.09. 12.32 MB 41 kB 12.36 MB %%%%%%%%%%%%%%%%%%%%%%%%%

————————+————-+—————————————-

estimated — — —

Type5 : For weekly

#vnstat –w

Example :

[[email protected] ~]# vnstat -w

eth0 / weekly

rxtx 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

#vnstat –m

Example :

[[email protected] ~]# vnstat -m

eth0 / monthly

monthrxtx total

————————-+————–+————————————–

Sep ’09 12.32 MB 41 kB 12.36 MB %%%%%%%%%%%%%%%%%%%%%%

————————-+————–+————————————–


Please comment your thoughts about VNSTAT.


Related concept:   Linux User info gathering commands