Skip to content

Instantly share code, notes, and snippets.

@corvax19
Created November 21, 2012 06:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corvax19/4123377 to your computer and use it in GitHub Desktop.
Save corvax19/4123377 to your computer and use it in GitHub Desktop.
vnstat - Network Traffic Monitor / http://goo.gl/68H3t
Configuration
Edit /etc/sysconfig/vnstat, enter:
# vi /etc/sysconfig/vnstat
Sample outputs:
VNSTAT_OPTIONS="-u -i eth0"
Edit /etc/vnstat.conf, enter:
# vi /etc/vnstat.conf
Set default interface to eth1:
Interface "eth1"
The file is self documented so set the options as per your local setup.
Save and close the file.
Create the database
You need to run the following command to create the database.
But, first set vnstat shell to /bin/bash using the chsh commad
# chsh -s /bin/bash vnstat
# grep --color vnstat /etc/passwd
# id vnstat
This is usually the first command used after a fresh install.
Use the runuser command to create the database for eth0 interface:
# runuser -l vnstat -g vnstat -c '/usr/bin/vnstat -u -i eth0'
To create the database for eth1 interface, run:
# runuser -l vnstat -g vnstat -c '/usr/bin/vnstat -u -i eth1'
Make sure vnstat user can not login i.e. refuse a login for vnstat user:
# chsh -s /sbin/nologin vnstat
# grep --color vnstat /etc/passwd
# id vnstat
Start vnstat service
Type the following chkconfig command to turn on vnstat service at boot time:
# chkconfig vnstat on
To start / stop / restart and control vnstart service, run:
# service vnstat start
# service vnstat stop
# service vnstat restart
# service vnstat status
How do I view stats?
The syntax is:
vnstat
vnstat -i {interface}
vnstat -i {interface} -option
vnstat -i {interface} -option1 -option2
$ vnstat
Sample outputs:
rx / tx / total / estimated
eth1:
Oct '12 76.68 GiB / 635.07 GiB / 711.74 GiB
Nov '12 31.14 GiB / 186.98 GiB / 218.12 GiB / 352.45 GiB
yesterday 1.35 GiB / 11.32 GiB / 12.67 GiB
today 1.34 GiB / 8.82 GiB / 10.16 GiB / 19.37 GiB
eth0:
Oct '12 629.87 GiB / 91.10 GiB / 720.97 GiB
Nov '12 181.99 GiB / 35.38 GiB / 217.37 GiB / 351.24 GiB
yesterday 11.25 GiB / 1.70 GiB / 12.95 GiB
today 8.76 GiB / 1.60 GiB / 10.36 GiB / 19.76 GiB
To see eth0 stats, enter:
$ vnstat -i eth0
To see daily stats for eth0, enter:
$ vnstat -i eth0 -d
Sample outputs:
eth0 / daily
day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
10/21/12 13.48 GiB | 1.80 GiB | 15.28 GiB | 1.48 Mbit/s
10/22/12 24.06 GiB | 3.44 GiB | 27.51 GiB | 2.67 Mbit/s
10/23/12 23.95 GiB | 3.45 GiB | 27.40 GiB | 2.66 Mbit/s
10/24/12 22.81 GiB | 3.30 GiB | 26.11 GiB | 2.53 Mbit/s
10/25/12 25.11 GiB | 3.48 GiB | 28.59 GiB | 2.78 Mbit/s
10/26/12 22.24 GiB | 3.01 GiB | 25.25 GiB | 2.45 Mbit/s
10/27/12 12.13 GiB | 1.67 GiB | 13.80 GiB | 1.34 Mbit/s
10/28/12 9.65 GiB | 1.67 GiB | 11.33 GiB | 1.10 Mbit/s
10/29/12 17.04 GiB | 3.13 GiB | 20.17 GiB | 1.96 Mbit/s
10/30/12 18.14 GiB | 3.18 GiB | 21.32 GiB | 2.07 Mbit/s
10/31/12 17.45 GiB | 3.05 GiB | 20.51 GiB | 1.99 Mbit/s
11/01/12 14.64 GiB | 2.74 GiB | 17.38 GiB | 1.69 Mbit/s
11/02/12 13.66 GiB | 2.51 GiB | 16.17 GiB | 1.57 Mbit/s
11/03/12 7.62 GiB | 1.34 GiB | 8.96 GiB | 870.25 kbit/s
11/04/12 5.63 GiB | 1.14 GiB | 6.77 GiB | 656.98 kbit/s
11/05/12 9.34 GiB | 2.08 GiB | 11.42 GiB | 1.11 Mbit/s
11/06/12 9.85 GiB | 2.13 GiB | 11.98 GiB | 1.16 Mbit/s
11/07/12 9.91 GiB | 2.14 GiB | 12.05 GiB | 1.17 Mbit/s
11/08/12 9.76 GiB | 2.12 GiB | 11.88 GiB | 1.15 Mbit/s
11/09/12 8.47 GiB | 1.81 GiB | 10.28 GiB | 998.23 kbit/s
11/10/12 5.54 GiB | 1.05 GiB | 6.58 GiB | 639.28 kbit/s
11/11/12 5.92 GiB | 1.12 GiB | 7.03 GiB | 682.98 kbit/s
11/12/12 8.74 GiB | 1.93 GiB | 10.67 GiB | 1.04 Mbit/s
11/13/12 8.77 GiB | 1.95 GiB | 10.72 GiB | 1.04 Mbit/s
11/14/12 8.93 GiB | 2.00 GiB | 10.93 GiB | 1.06 Mbit/s
11/15/12 10.53 GiB | 2.13 GiB | 12.65 GiB | 1.23 Mbit/s
11/16/12 13.58 GiB | 2.31 GiB | 15.89 GiB | 1.54 Mbit/s
11/17/12 11.09 GiB | 1.60 GiB | 12.70 GiB | 1.23 Mbit/s
11/18/12 11.25 GiB | 1.70 GiB | 12.95 GiB | 1.26 Mbit/s
11/19/12 8.81 GiB | 1.61 GiB | 10.42 GiB | 1.92 Mbit/s
------------------------+-------------+-------------+---------------
estimated 16.69 GiB | 3.06 GiB | 19.74 GiB |
To see hourly network stats, enter:
$ vnstat -i eth0 -h
To see monthly network stats, enter:
$ vnstat -i eth0 -m
To see weekly network stats, enter:
$ vnstat -i eth0 -w
To see top 10 network, stats:
$ vnstat -t
$ vnstat -i eth0 -t
To see short output:
$ vnstat -i eth0 -s
To calculate traffic, enter:
$ vnstat -i eth0 -tr
Sample outputs:
2038 packets sampled in 5 seconds
Traffic average for eth0
rx 1.08 Mbit/s 202 packets/s
tx 273.60 kbit/s 204 packets/s
To see transfer rate in real time for eth0, enter:
$ vnstat -i eth0 -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment