How to Monitor Network Bandwidth with vnstat

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. However, in Linux at least a 2.2 series kernel is required.
It is very simple to install and use. It can monitor multiple network interfaces at the same time. It will display the output summary in hourly, daily, weekly and as well as monthly basis. And it can be used without root permissions.
Install vnstat
On Debian/Ubuntu:
[email protected]# sudo apt-get install vnstat
On RHEL/CentOS:
vnstat will not be found in Official repositories, so add EPEL repository to install vnstat:
[[email protected] ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Install vnstat with following command:
[[email protected] ~]# yum install vnstat -y
Usage
To view all network interfaces statistics, enter the following command:
[email protected]# vnstat
This shows network bandwidth usage of all network interfaces:
rx      /      tx      /     total    /   estimated
eth1:
       Jul '13      4.77 MiB  /     204 KiB  /    4.97 MiB  /       0 KiB
       today      4.77 MiB  /     204 KiB  /    4.97 MiB  /      --    

 wlan0: Not enough data available yet.
 eth0: Not enough data available yet.
To view a particular interface bandwidth usage, enter the command:
[email protected]# vnstat -i eth1
The above command will display the bandwidth usage of eth1:
Database updated: Thu Jul  4 13:26:10 2013
   eth1 since 07/04/13
          rx:  4.82 MiB      tx:  249 KiB      total:  5.07 MiB
   
monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Jul '13      4.82 MiB |     249 KiB |    5.07 MiB |    0.13 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        --     |      --     |      --     |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
         today      4.82 MiB |     249 KiB |    5.07 MiB |    0.86 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        --     |      --     |      --     |
To view the hourly usage, use the parameter “-h” without quotes:
[email protected]# vnstat -i eth1 -h
 eth1                                                                  13:31 
  ^                                                                      r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
  |                                                                       r     
 -+---------------------------------------------------------------------------> 
  |  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 (KiB)   tx (KiB)      h  rx (KiB)   tx (KiB)      h  rx (KiB)   tx (KiB) 
14          0          0    22          0          0    06          0          0
15          0          0    23          0          0    07          0          0
16          0          0    00          0          0    08          0          0
17          0          0    01          0          0    09          0          0
18          0          0    02          0          0    10          0          0
19          0          0    03          0          0    11          0          0
20          0          0    04          0          0    12          0          0
21          0          0    05          0          0    13       4964        290
To view daily usage, use the parameter “-d”:
[email protected]# vnstat -i eth1 -d 

eth1  /  daily
         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      07/04/13      4.82 MiB |     249 KiB |    5.07 MiB |    0.86 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        --     |      --     |      --     |
To view weekly usage, use the parameter “-w”:
[email protected]# vnstat -i eth1 -w

 eth1  /  weekly
                      rx      |     tx      |    total    |   avg. rate
   ---------------------------+-------------+-------------+---------------
    last 7 days      4.85 MiB |     290 KiB |    5.13 MiB |    0.07 kbit/s
   current week      4.85 MiB |     290 KiB |    5.13 MiB |    0.14 kbit/s
   ---------------------------+-------------+-------------+---------------
      estimated        --     |      --     |      --     |
And to view monthly usage, use “-m”:
[email protected]# vnstat -i eth1 -m

 eth1  /  monthly

       month        rx      |     tx      |    total    |   avg. rate
    ------------------------+-------------+-------------+---------------
      Jul '13      4.85 MiB |     290 KiB |    5.13 MiB |    0.14 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated        --     |      --     |      --     |
To see top ten network bandwidth usage of eth1:
[email protected]# vnstat -i eth1 -t
To view the bandwidth usage of 5 seconds, enter the following command:
[email protected]# vnstat -i eth1 -tr
To view the usage of 10 seconds, enter the following command:
[email protected]# vnstat -i eth1 -tr 10
Finally to see the real live bandwidth usage of eth1:
[email protected]# vnstat -i eth1 -l
This command will collect the network bandwidth usage of eth1. You can stop the process by pressing CTRL+C at any time.
Sample Output:
Monitoring eth1...    (press CTRL-C to stop)

   rx:        0 kbit/s     0 p/s          tx:        0 kbit/s     0 p/s
   rx:        0 kbit/s     0 p/s          tx:        0 kbit/s     0 p/s^C

 eth1  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                    17.96 MiB  |        4.48 MiB
--------------------------------------+------------------
          max            3.78 Mbit/s  |      420 kbit/s
      average           31.62 kbit/s  |     7.90 kbit/s
          min               0 kbit/s  |        0 kbit/s
--------------------------------------+------------------
  packets                      22511  |           21780
--------------------------------------+------------------
          max                336 p/s  |         206 p/s
      average                  4 p/s  |           4 p/s
          min                  0 p/s  |           0 p/s
--------------------------------------+------------------
  time                 77.55 minutes
Hope you have a basic idea about vnstat.
Happy Monitoring!
  • 86 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

Setup ownCloud On RHEL, CentOS, Scientific Linux 6.5

ownCloud is a free Open Source software, used to setup your own personal cloud for file sharing,...

How do I see how much free ram I really have?

Linux Ate My RAM Don't panic. Your RAM is fine What's going on?Linux is borrowing unused memory...

MySQL - connect to a remote database

This tutorial will walk you through setting up a user on your MySQL server to connect remotely....

How to copy my files to my vps

Prerequisites: FileZilla - we will use FileZilla which can be downloaded from here fro free:...

Setup Fileserver Using Pydio On CentOS 6.5/6.4

Pydio, formerly known as AjaXplorer, is an open source application that can be used to setup...