Jul 052010
 

From webhostingwalk.com

vnStat is a console-based network traffic monitor. It keeps a log of hourly, daily and monthly network traffic for the selected interface(s). However, it isn’t a packet sniffer. The traffic information is analyzed from the proc(5) and sys filesystems depending on availability. That way vnStat can be used even without root permissions on most systems.

A new database can be created with the following command:

vnstat -u -i eth0

Show traffic for days.

# vnstat -d

eth0  /  daily

         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      06/30/10      3.84 MiB |    3.29 MiB |    7.13 MiB |    1.22 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated         5 MiB |       5 MiB |      10 MiB |

To list additional debug output:

# vnstat -D


Config file: /etc/vnstat.conf
  c: Interface "eth0"
   -> "Interface": "eth0"
  c: DatabaseDir "/var/lib/vnstat"
   -> "DatabaseDir": "/var/lib/vnstat"
  c: Locale "-"
   -> "Locale": "-"

To show traffic for the last 24 hours:

# vnstat -h

eth0                                                                     13:19
  ^                                                                       r
  |                                                                       r
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
-+--------------------------------------------------------------------------->
  |  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        153        195
21          0          0    05          0          0    13       3779       3174

Select one specific interface and apply actions to only it.

# vnstat -i eth0

Show list of currently available interfaces.

# vnstat -iflist

Available interfaces: lo eth0 eth1 sit0 vmnet1 vmnet8

To Display current transfer rate for the selected interface in real time until interrupted. Statistics will be shown after interruption if the run- time was more than 10 seconds.

# vnstat -l

Monitoring eth0...    (press CTRL-C to stop)

   rx:        4 kbit/s     2 p/s          tx:        4 kbit/s     3 p/s

To show traffic for months.

# vnstat -m

eth0  /  monthly

       month        rx      |     tx      |    total    |   avg. rate
    ------------------------+-------------+-------------+---------------
      Jun '10      3.84 MiB |    3.29 MiB |    7.13 MiB |    0.02 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated         3 MiB |       3 MiB |       6 MiB |

To show traffic summary for selected interface using one line with a parseable format.

# vnstat --oneline

1;eth0;06/30/10;3.84 MiB;3.29 MiB;7.13 MiB;1.22 kbit/s;Jun '10;3.84 MiB;3.29 MiB;7.13 MiB;0.02 kbit/s;3.84 MiB;3.29 MiB;7.13 MiB

Show all time top10 traffic days.

# vnstat -t

To calculate how much traffic goes through the selected interface during the given time seconds. The time will be 5 seconds if a number parameter isn’t included.

54 packets sampled in 5 seconds
Traffic average for eth0

      rx         6.40 kbit/s             5 packets/s
      tx         6.40 kbit/s             5 packets/s

To update all enabled databases.

# vnstat -u

To show traffic for 7 days, current and previous week.

# vnstat -w

eth0  /  weekly

                      rx      |     tx      |    total    |   avg. rate
   ---------------------------+-------------+-------------+---------------
    last 7 days      3.84 MiB |    3.29 MiB |    7.13 MiB |    0.10 kbit/s
   current week      3.84 MiB |    3.29 MiB |    7.13 MiB |    0.26 kbit/s
   ---------------------------+-------------+-------------+---------------
      estimated         8 MiB |       8 MiB |      16 MiB |

To delete database of interface eth2 and stop monitoring it.

# vnstat -i eth2 --delete
Share This!
 Posted by at 11:19 am

Sorry, the comment form is closed at this time.