One of the better applications for monitoring transfer usage on Linux is vnStat, particularly useful when we pay for transfer. vnStat is a console application that measures traffic on the network interfaces we choose, saving the data to a database. Its undoubted advantages are: simple configuration, very low resource usage, and no requirement for additional applications such as a web server or database server.
Installation and configuration is dead simple - vnStat is available as a ready-made package in many distributions. After installing, we need to create a database for vnstat:
# vnstat -u -i interface_name
If we want to additionally monitor another interface, we should similarly create a database for it, changing the interface name.
After creating the database, restart the program's daemon. Now we need to wait a dozen or so minutes for the program to collect the necessary data, otherwise it will return an error.
Displaying statistics
- hourly report
$ vnstat -h
eth0 19:24
^ 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
| r t t t t t t t t
| t r t t t t t t t t t
-+--------------------------------------------------------------------------->
| 20 21 22 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
h rx (KiB) tx (KiB) h rx (KiB) tx (KiB) h rx (KiB) tx (KiB)
20 34819 213304 04 79446 29671 12 271433 1760062
21 88055 548890 05 78617 110562 13 342435 2655130
22 80606 211012 06 78555 222187 14 83603 2068202
23 82407 238540 07 92371 4974 15 36793 2552059
00 80762 153430 08 1161825 22687 16 29915 2950034
01 81389 131208 09 119667 315760 17 63289 5443846
02 80562 80080 10 122242 444005 18 83502 4927155
03 78994 176507 11 126445 1841216 19 14074 853048
$ vnstat -d
eth0 / daily
day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
04/09/11 105.69 MiB | 4.13 GiB | 4.23 GiB | 410.83 kbit/s
04/10/11 3.07 GiB | 10.90 GiB | 13.97 GiB | 1.36 Mbit/s
04/11/11 82.07 MiB | 4.43 GiB | 4.51 GiB | 437.66 kbit/s
04/12/11 6.35 GiB | 12.37 GiB | 18.72 GiB | 1.82 Mbit/s
04/13/11 3.81 GiB | 29.56 GiB | 33.37 GiB | 3.24 Mbit/s
04/14/11 3.35 GiB | 21.63 GiB | 24.98 GiB | 2.43 Mbit/s
04/15/11 364.39 MiB | 19.35 GiB | 19.70 GiB | 1.91 Mbit/s
04/16/11 3.18 GiB | 19.18 GiB | 22.37 GiB | 2.17 Mbit/s
04/17/11 1.95 GiB | 36.01 GiB | 37.96 GiB | 3.69 Mbit/s
04/18/11 1.37 GiB | 18.82 GiB | 20.19 GiB | 1.96 Mbit/s
04/19/11 563.78 MiB | 10.03 GiB | 10.58 GiB | 1.03 Mbit/s
04/20/11 208.45 MiB | 14.26 GiB | 14.46 GiB | 1.40 Mbit/s
04/21/11 87.38 MiB | 4.64 GiB | 4.72 GiB | 458.53 kbit/s
04/22/11 84.87 MiB | 4.89 GiB | 4.97 GiB | 482.41 kbit/s
04/23/11 4.64 GiB | 19.37 GiB | 24.01 GiB | 2.33 Mbit/s
04/24/11 1.89 GiB | 20.60 GiB | 22.49 GiB | 2.18 Mbit/s
04/25/11 112.11 MiB | 6.09 GiB | 6.20 GiB | 602.28 kbit/s
04/26/11 1.56 MiB | 6.10 MiB | 7.65 MiB | 0.73 kbit/s
04/27/11 1.78 MiB | 5.16 MiB | 6.94 MiB | 0.66 kbit/s
04/28/11 4.04 MiB | 3.89 MiB | 7.93 MiB | 0.75 kbit/s
04/29/11 1.70 MiB | 4.24 MiB | 5.94 MiB | 0.56 kbit/s
04/30/11 1.13 MiB | 2.68 MiB | 3.81 MiB | 0.36 kbit/s
05/01/11 1.50 GiB | 4.13 GiB | 5.63 GiB | 546.53 kbit/s
05/02/11 89.66 MiB | 4.49 GiB | 4.57 GiB | 444.15 kbit/s
05/03/11 58.78 MiB | 2.78 GiB | 2.84 GiB | 275.63 kbit/s
05/04/11 349.57 MiB | 6.16 GiB | 6.50 GiB | 631.43 kbit/s
05/05/11 2.96 GiB | 25.50 GiB | 28.47 GiB | 3.42 Mbit/s
------------------------+-------------+-------------+---------------
estimated 3.66 GiB | 31.55 GiB | 35.21 GiB |
$ vnstat -w
eth0 / weekly
rx | tx | total | avg. rate
---------------------------+-------------+-------------+---------------
last 7 days 4.95 GiB | 43.07 GiB | 48.02 GiB | 684.74 kbit/s
last week 1.62 GiB | 10.24 GiB | 11.86 GiB | 164.55 kbit/s
current week 3.45 GiB | 38.93 GiB | 42.38 GiB | 1.08 Mbit/s
---------------------------+-------------+-------------+---------------
estimated 6.37 GiB | 71.88 GiB | 78.24 GiB |
$ vnstat -m
eth0 / monthly
month rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Apr '11 31.19 GiB | 256.28 GiB | 287.47 GiB | 930.36 kbit/s
May '11 4.95 GiB | 42.97 GiB | 47.91 GiB | 968.06 kbit/s
------------------------+-------------+-------------+---------------
estimated 31.90 GiB | 277.18 GiB | 309.08 GiB |
$ vnstat -l -i eth0
Monitoring eth0... (press CTRL-C to stop)
rx: 92 kbit/s 272 p/s tx: 5.17 Mbit/s 448 p/s
eth0 / traffic statistics
rx | tx
--------------------------------------+------------------
bytes 256 KiB | 14.70 MiB
--------------------------------------+------------------
max 100 kbit/s | 5.99 Mbit/s
average 78.77 kbit/s | 4.63 Mbit/s
min 64 kbit/s | 4.03 Mbit/s
--------------------------------------+------------------
packets 6093 | 10434
--------------------------------------+------------------
max 290 p/s | 520 p/s
average 234 p/s | 401 p/s
min 190 p/s | 350 p/s
--------------------------------------+------------------
time 26 seconds
In summary, it's worth mentioning graphical front-ends for the vnStat program. The first application that creates a graphical presentation of the data is vnstati, the second is the vnstat PHP frontend. vnstati generates charts in png format, while the second application generates charts in the form of a web page using php. I personally prefer the vnstat PHP frontend, which is why this frontend is described in more detail here: vnstat PHP frontend - a graphical interface for vnStat.