Traffic Monitoring with vnStat

Interested in how much bandwidth you are using? vnStat is a simple command line utility to track network traffic on a Linux computer. vnStat is easy to set up and use on Ubuntu, and works well on both server and desktop systems.

Run these three commands to install vnStat and set up permissions so every user can run it:

sudo apt-get install vnstat
sudo chmod o+x /usr/bin/vnstat
sudo chmod o+wx /var/lib/vnstat/

You need to find the name of the network interface you want to monitor. Most of the time it will be called eth0, run

ifconfig

to check if you are not sure. Then run this command, replacing eth0 with the name of your network interface:

vnstat -u -i eth0

That command creates a cron job (scheduled task) that will run every few minutes and collect traffic data for vnStat.

Check the collected data by running vnstat on a command line. It will bring up the daily usage information:

Database updated: Thu Aug 30 13:40:01 2007

        eth0

           received:          90.65 MB (11.9%)
        transmitted:         666.12 MB (88.1%)
              total:         756.77 MB

                        rx     |     tx     |  total
        -----------------------+------------+-----------
        yesterday     49.94 MB |  378.44 MB |  428.38 MB
            today     17.27 MB |  125.30 MB |  142.57 MB
        -----------------------+------------+-----------
        estimated        29 MB |     218 MB |     247 MB

Run vnstat -h to see an hourly graph:

 eth0                                                                     13:40
  ^   t
  |   t
  |   t
  |   t
  |   t           t                                                     t
  |   t  t  t     t        t                                t  t     t  t
  |   t  t  t  t  t  t  t  t  t  t                 t  t     t  t     t  t
  |   t  t  t  t  t  t  t  t  t  t  t        t  t  t  t  t  t  t  t  t  t  t
  |   t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t
  |  rt  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t
 -+--------------------------------------------------------------------------->
  |  14 15 16 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13    

 h   rx (kB)    tx (kB)      h   rx (kB)    tx (kB)      h   rx (kB)    tx (kB)
14       2543      21517    22       1286       9950    06       1304       9431
15       1628      11561    23       1406       9223    07       1147       8576
16       1770      12431    00        999       7849    08       1775      12656
17       1388       9518    01        673       5071    09       1485      11738
18       1870      13693    02        932       6089    10       1063       7514
19       1392       9417    03        882       7620    11       1530      11656
20       1522      10194    04       1024       7629    12       2118      14688
21       1838      11744    05       1429       9662    13       1330       8130

vnStat has many more options as well. Run

vnstat –help

to more ways to look at the data. Also check out the screenshots section of the vnStat website for examples.
Start and test vnstat:
Note which interfaces are active on your PC.

vnstat -u -i eth0
vnstat -u -i eth1

Now you can generate text reports of your monthly bandwidth usage. I use eth1 in the following examples, but you may be using eth0 or both eth0 and eth1.
Daily bandwidth report.

vnstat -i eth1 -d

Hourly bandwidth report.

vnstat -i eth1 -h

Monthly bandwidth report.

vnstat -i eth1 -m

Real time speed report.

vnstat -i eth1 -l
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s