vnstat通/proc来监控流量,无需root权限,提供每日、每月等报表,并有php前台扩展。
经过几个月运行发现有时vnstat -d 只能看最近几天的
http://humdi.net/vnstat/
wget http://humdi.net/vnstat/vnstat-1.6.tar.gz
tar zxvf vnstat-1.6.tar.gz
cd vnstat-1.6
make && make install ; vnstat –testkernel && vnstat -u -i eth0
如果用户在一个64位平台上编译,应改用make 64bit命令.
添加crontab
crontab -e
0-55/5 * * * * if [ -x /usr/bin/vnstat ] && [ `ls/var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi
vnStat 1.6 by Teemu Toivola
-q, --query query database
-h, --hours show hours
-d, --days show days
-m, --months show months
-w, --weeks show weeks
-t, --top10 show top10
-s, --short use short output
-u, --update update database
-i, --iface change interface (default: eth0)
-?, --help short help
-v, --version show version
-tr, --traffic calculate traffic
-l, --live show transfer rate in real time
See also "--longhelp" for complete options list and "man vnstat".
|
$ vnstat
Database updated: Sun Dec 2 22:20:01 2007
inet (eth0)
received: 735.00 GB (48.9%)
transmitted: 769.38 GB (51.1%)
total: 1.47 TB
rx | tx | total
-----------------------+------------+-----------
yesterday 23.35 MB | 20.25 MB | 43.60 MB
today 27.47 MB | 21.37 MB | 48.84 MB
-----------------------+------------+-----------
estimated 29 MB | 22 MB | 51 MB
|
(with 2 interfaces)
$ vnstat
rx / tx / total / estimated
Internet (eth1):
yesterday 209.36 MB / 322.88 MB / 532.24 MB
today 1.99 GB / 2.46 GB / 4.46 GB / 4.67 GB
Local (eth0):
yesterday 248.27 MB / 4.63 GB / 4.87 GB
today 2.31 GB / 4.21 GB / 6.52 GB / 6.83 GB
|
$ vnstat -h
inet (eth0) 22:15
^ r
| rt r
| rt rt
| rt rt
| r rt rt
| rt r rt rt
| rt rt rt rt rt
| rt rt rt r r rt r rt r rt rt rt
| rt rt rt r rt rt rt rt rt rt rt rt rt
| rt rt rt rt r r r r r rt rt rt rt rt rt rt rt rt rt
-+--------------------------------------------------------------------------->
| 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
h rx (kB) tx (kB) h rx (kB) tx (kB) h rx (kB) tx (kB)
23 1,352 1,219 07 277 151 15 1,352 1,165
00 2,281 2,140 08 402 158 16 1,487 878
01 1,485 1,261 09 290 155 17 1,752 1,559
02 648 522 10 589 185 18 1,455 1,001
03 392 261 11 650 202 19 2,332 1,835
04 323 240 12 907 350 20 3,881 3,619
05 311 179 13 1,234 1,044 21 3,695 3,237
06 281 173 14 1,221 812 22 675 591
|
$ vnstat -d
inet (eth0) / daily
day rx | tx | total
------------------------+-------------+----------------------------------------
03.11. 26.57 MB | 27.39 MB | 53.97 MB %%%%%%:::::::
04.11. 22.23 MB | 16.71 MB | 38.94 MB %%%%%::::
05.11. 31.38 MB | 23.35 MB | 54.74 MB %%%%%%%::::::
06.11. 35.17 MB | 26.85 MB | 62.02 MB %%%%%%%%%::::::
07.11. 42.65 MB | 34.19 MB | 76.84 MB %%%%%%%%%%%::::::::
08.11. 36.65 MB | 26.75 MB | 63.40 MB %%%%%%%%%::::::
09.11. 35.01 MB | 27.45 MB | 62.47 MB %%%%%%%%:::::::
10.11. 24.48 MB | 22.72 MB | 47.20 MB %%%%%%:::::
11.11. 26.04 MB | 19.91 MB | 45.95 MB %%%%%%:::::
12.11. 27.89 MB | 18.73 MB | 46.61 MB %%%%%%%::::
13.11. 33.82 MB | 24.52 MB | 58.35 MB %%%%%%%%::::::
14.11. 39.11 MB | 31.76 MB | 70.86 MB %%%%%%%%%::::::::
15.11. 41.57 MB | 36.23 MB | 77.80 MB %%%%%%%%%%:::::::::
16.11. 36.93 MB | 33.51 MB | 70.44 MB %%%%%%%%%::::::::
17.11. 25.79 MB | 23.87 MB | 49.66 MB %%%%%%::::::
18.11. 29.51 MB | 22.50 MB | 52.01 MB %%%%%%%::::::
19.11. 43.46 MB | 32.91 MB | 76.38 MB %%%%%%%%%%%::::::::
20.11. 51.90 MB | 47.82 MB | 99.72 MB %%%%%%%%%%%%%::::::::::::
21.11. 38.77 MB | 34.21 MB | 72.98 MB %%%%%%%%%%::::::::
22.11. 34.54 MB | 31.22 MB | 65.76 MB %%%%%%%%::::::::
23.11. 22.61 MB | 21.16 MB | 43.76 MB %%%%%:::::
24.11. 22.49 MB | 20.84 MB | 43.34 MB %%%%%:::::
25.11. 31.60 MB | 26.50 MB | 58.10 MB %%%%%%%%::::::
26.11. 38.23 MB | 33.84 MB | 72.07 MB %%%%%%%%%%::::::::
27.11. 43.54 MB | 41.88 MB | 85.42 MB %%%%%%%%%%%::::::::::
28.11. 38.86 MB | 30.87 MB | 69.73 MB %%%%%%%%%::::::::
29.11. 40.16 MB | 33.64 MB | 73.79 MB %%%%%%%%%%::::::::
30.11. 32.73 MB | 28.67 MB | 61.40 MB %%%%%%%%:::::::
01.12. 23.35 MB | 20.25 MB | 43.60 MB %%%%%:::::
02.12. 27.27 MB | 21.21 MB | 48.47 MB %%%%%%%:::::
------------------------+-------------+----------------------------------------
estimated 29 MB | 22 MB | 51 MB
|
$ vnstat -m
inet (eth0) / monthly
month rx | tx | total
-------------------------+--------------+--------------------------------------
Jan '07 1.33 GB | 1.25 GB | 2.58 GB %%%%%%%%%::::::::
Feb '07 1.31 GB | 1.51 GB | 2.82 GB %%%%%%%%%::::::::::
Mar '07 1.54 GB | 1.66 GB | 3.20 GB %%%%%%%%%%%:::::::::::
Apr '07 1.27 GB | 1.13 GB | 2.40 GB %%%%%%%%::::::::
May '07 1.17 GB | 1.31 GB | 2.48 GB %%%%%%%%:::::::::
Jun '07 920.61 MB | 2.00 GB | 2.90 GB %%%%%%:::::::::::::
Jul '07 917.21 MB | 763.12 MB | 1.64 GB %%%%%%:::::
Aug '07 915.59 MB | 905.99 MB | 1.78 GB %%%%%%::::::
Sep '07 926.10 MB | 678.70 MB | 1.57 GB %%%%%%::::
Oct '07 1.00 GB | 714.00 MB | 1.69 GB %%%%%%:::::
Nov '07 0.99 GB | 842.16 MB | 1.81 GB %%%%%%%:::::
Dec '07 50.62 MB | 41.46 MB | 92.07 MB
-------------------------+--------------+--------------------------------------
estimated 808 MB | 663 MB | 1.44 GB
|
$ vnstat -t
inet (eth0) / top 10
# day rx | tx | total
-------------------------------+-------------+---------------------------------
1 26.03.06 6.41 GB | 10.83 GB | 17.24 GB %%%%%%%:::::::::::
2 05.02.04 8.31 GB | 7.08 GB | 15.39 GB %%%%%%%%%:::::::
3 04.02.05 7.96 GB | 6.21 GB | 14.17 GB %%%%%%%%::::::
4 04.09.05 8.09 GB | 5.22 GB | 13.30 GB %%%%%%%%:::::
5 04.11.03 4.52 GB | 5.96 GB | 10.47 GB %%%%::::::
6 26.06.05 4.12 GB | 6.10 GB | 10.22 GB %%%%::::::
7 02.11.03 7.18 GB | 2.79 GB | 9.97 GB %%%%%%%:::
8 31.01.05 3.68 GB | 5.99 GB | 9.66 GB %%%%::::::
9 28.08.03 5.93 GB | 3.69 GB | 9.62 GB %%%%%%::::
10 23.12.03 4.36 GB | 5.23 GB | 9.59 GB %%%%%:::::
-------------------------------+-------------+---------------------------------
|
$ vnstat -w
Local (eth0) / weekly
rx | tx | total
----------------------------+---------------+--------------
last 7 days 4.83 GB | 18.82 GB | 23.65 GB
last week 2.52 GB | 14.58 GB | 17.10 GB
current week 2.31 GB | 4.24 GB | 6.55 GB
----------------------------+---------------+--------------
estimated 17.66 GB | 32.36 GB | 50.02 GB
|
$ vnstat -tr
10386 packets sampled in 5 seconds
Traffic average for eth1
rx 112.21 kB/s 620 packets/s
tx 1444.77 kB/s 1456 packets/s
|
$ vnstat -l
Monitoring eth0... (press CTRL-C to stop)
rx: 430.68 kB/s 291 p/s tx: 10.21 kB/s 147 p/s
eth0 / traffic statistics
rx | tx
--------------------------------------+----------------------------------------
bytes 32.79 MB | 957 kB
--------------------------------------+----------------------------------------
max 656.39 kB/s | 90.50 kB/s
average 419.78 kB/s | 11.97 kB/s
min 288.37 kB/s | 7.03 kB/s
--------------------------------------+----------------------------------------
packets 23298 | 12348
--------------------------------------+----------------------------------------
max 732 p/s | 609 p/s
average 291 p/s | 154 p/s
min 195 p/s | 100 p/s
--------------------------------------+----------------------------------------
time 1.33 minutes
|
No Responses (yet)
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.