Vnstat: 简单实用的网络流量统计工具

28 十一
2010
# 作者: riku / 本文采用CC BY-NC-SA 2.5协议授权,转载请注明本文链接

最近在邮件列表里看到有人询问如何统计网络流量的问题,很多人推荐了 mrtg 等工具,其实个人一直在用 Vnstat 这款小软件,它的特点是简单实用,配置方便 。另外,它还自带了 vnstati 命令,通过它可以直接可以输出流量统计图,我的 VPS Server 上都是用这款工具进行统计流量,你可以到这里看一下效果。

官方主页: http://humdi.net/vnstat

# Ubuntu 安装: (其本上其它发行版的包管理程序中也都包含了这款软件,请自行安装)

sudo apt-get install vnstat vnstati

安装好后运行以下命令初始化数据库

sudo vnstat -u -i eth0

启动 daemon 进程,(有些发行版可能需要通过 cron 来定期执行)

sudo /etc/init.d/vnstat start

默认开机启动

sudo update-rc.d vnstat enable

# 使用

1 命令行方式:直接输入 vnstat ,或后面加相应的参数,比如 vnstat -d 是显示日流量信息, vnstat -m 是月流量信息,其它参数请 man vnstat 。

效果图:

2 输出到图形:使用 vnstati 命令,更多详细的参数可以请 man vnstati。

比如输出每月的流量统计图。

vnstati -i eth0 - -months - -output /dir/month.png

效果图:

想要生成网页的话,就写一条 cron 脚本 ,定时输出网页,然后自已写一个 html 文件来调用这些图片就可以了,具体就不详述了。

作者:riku

Bio: 关注新网络、Web2.0、移动应用;Nexus S/Andorid,iPad,FreeBSD,Ubuntu 用户;伪设计师,好推墙运动。
链接:Blog - Twitter - Facebook - 此作者的更多文章

12 Responses to Vnstat: 简单实用的网络流量统计工具

Avatar

Yousri

Google Chrome 9.0.587.0 Google Chrome 9.0.587.0 GNU/Linux GNU/Linux

十一月 28th, 2010 at 11:56 下午

嗯 这个不错 服务器察看流量使用必备
还有相应的支持php的扩展支持在线网页更直观察看

[Reply]

Avatar

AlleNny

Google Chrome 7.0.517.44 Google Chrome 7.0.517.44 GNU/Linux GNU/Linux

十一月 29th, 2010 at 12:21 上午

貌似iptables也可以简单的查看每次开机后的流量

[Reply]

Avatar

yixf

Firefox 3.6.12 Firefox 3.6.12 Ubuntu 10.10 x64 Ubuntu 10.10 x64

十一月 29th, 2010 at 8:43 上午

man了一下,没发现有--output这个选项呀……
PS:Ubuntu 10.10

[Reply]

Google Chrome 9.0.587.0 Google Chrome 9.0.587.0 GNU/Linux GNU/Linux

riku Reply:

@yixf, 有, man vnstati

-o, --output file
Write png image to file and exit. Output can be directed to stdout by giving "-" as filename.

[Reply]

Firefox 3.6.12 Firefox 3.6.12 Ubuntu 10.10 x64 Ubuntu 10.10 x64

yixf Reply:

@riku,
man vnstat没有output选项;
man vnstati有。
两者什么区别?

PS:
文章中的
vnstat -i eth0 – -months – -output /dir/month.png
我没有执行成功;把vnstat换成vnstati就可以了。

[Reply]

Google Chrome 9.0.587.0 Google Chrome 9.0.587.0 GNU/Linux GNU/Linux

riku Reply:

@yixf, 抱歉,是我写错了。已改正。

vnstat 是命令行工具
vnstati 是图形输出工具

[Reply]

Avatar

freetstar

Google Chrome 9.0.587.0 Google Chrome 9.0.587.0 Windows 7 Windows 7

十一月 29th, 2010 at 8:53 上午

号东西哈

[Reply]

Avatar

Mephisto

Chromium 9.0.590.0 Chromium 9.0.590.0 Ubuntu 10.04 Ubuntu 10.04

十一月 29th, 2010 at 9:05 上午

我想要流量控制,如p2p终结者.....

[Reply]

Google Chrome 9.0.587.0 Google Chrome 9.0.587.0 GNU/Linux GNU/Linux

riku Reply:

@Mephisto, 这个只是监控,没有控制。控制请用 firewall 软件,如 iptables 等等。

[Reply]

Avatar

yixf

Firefox 3.6.12 Firefox 3.6.12 Ubuntu 10.10 x64 Ubuntu 10.10 x64

十一月 29th, 2010 at 12:42 下午

刚刚又发现一个问题:
ntstat有--weeks选项;而ntstati却没有……

[Reply]

Google Chrome 9.0.587.0 Google Chrome 9.0.587.0 GNU/Linux GNU/Linux

riku Reply:

@yixf, 这也没办法了,程序限制。

[Reply]

Avatar

vpsinfo:VPS状态查看工具 | 神医溜光椅

WordPress 3.0.2 WordPress 3.0.2

十二月 3rd, 2010 at 2:18 上午

[...]                  以上参考自:http://wowubuntu.com/vnstat.html [...]

Comment Form

top

无觅相关文章插件,快速提升流量