Track summarized network traffic on a server with vnStat

digitalocean-linodeHow can I keep a log of hourly, daily, monthly network traffic for my server as its monthly traffic is limited? vnStat is a tool that designed for this. 

vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources.

Install and Config vnStat

On Debian/Ubuntu , the installation is as simple as,

# sudo apt-get install vnstat

On RHEL/CentOS, you may need the EPEL repository to run a quick yum install. Alternatively, you can checkout the source code, and install it from scratch.

When installation finished, edit “/etc/vnstat.conf”, and set the default interface it checks,

Interface "eth0"

You can check more than one interface. Then, start vnstat to run as a daemon,

$ sudo /etc/init.d/vnstat start

To see daily stats for eth0, enter:

$ vnstat -i eth0 -d
         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      07/02/14     34.09 MiB |  158.75 MiB |  192.83 MiB |   18.28 kbit/s
      07/03/14     54.45 MiB |  209.59 MiB |  264.04 MiB |   25.03 kbit/s
      07/04/14     11.71 MiB |   78.21 MiB |   89.92 MiB |   17.04 kbit/s

To see hourly network stats, enter,

$ vnstat -i eth0 -h
 eth0                                                                     12:00
  ^   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 rt  t     t  t  t  t  t  t  t  t  t  t  t  t     t  t  t  t  t  t
  |  rt rt  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t
  |  rt rt  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t
  |  rt rt rt  t  t  t  t rt  t rt  t  t  t  t  t rt  t  t  t  t  t rt rt
 -+--------------------------------------------------------------------------->
  |  13 14 15 16 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07 08 09 10 11 12

 h  rx (KiB)   tx (KiB)      h  rx (KiB)   tx (KiB)      h  rx (KiB)   tx (KiB)
13       5783      11822    21       1057       6053    05        891       4250
14       4989       9481    22       1419       5436    06        886       5524
15       1707       8085    23        602       5170    07        802       5631
16        653       4341    00        620       5211    08       1157       6046
17       1148       6821    01        486       4999    09        896       8989
18        877       7146    02        708       6786    10       1425       8191
19        920       6261    03        601       7247    11       1477       9134
20       1741       8795    04       2046       8077    12          0          0
Share Button

Leave a comment

Your email address will not be published. Required fields are marked *