V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
phttc
V2EX  ›  Linux

iptraf 统计流量

  •  
  •   phttc · 2016-04-08 21:20:23 +08:00 · 4829 次点击
    这是一个创建于 2930 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想要统计每个端口的流量信息,看到个工具 iptraf ,用了一下感觉不错。

    我想将它开在后台,作为流量统计工具。于是执行 iptraf -s eth0 -L iptrafss.log -B

    问题出现了!第一, iptraf -h 里只告诉我们怎么在后台开启服务,没说怎么结束,我试着-x ,未能识别。那我只能用 kill 去杀了。这时候查看日志,里面只有一条服务启动信息,没有任何统计信息。如果是在字符界面里统计,正常退出的话,是可以输出日志的。。。

    有一种方法是设置超时时间,这太蠢了吧?如果我突然想去看统计信息,那还是无解。

    6 条回复    2017-02-03 08:24:46 +08:00
    xuboying
        1
    xuboying  
       2016-04-08 21:31:06 +08:00 via Android
    screen 里运行?
    phttc
        2
    phttc  
    OP
       2016-04-08 21:33:08 +08:00
    @xuboying 什么意思? iptraf 有界面模式的,但是我希望它运行成后台服务进行流量统计
    xuboying
        3
    xuboying  
       2016-04-08 21:37:37 +08:00 via Android
    @phttc 先起一个 screen ,然后里面执行 iptraf ... | tee logfile
    phttc
        4
    phttc  
    OP
       2016-04-08 21:43:35 +08:00
    @xuboying 这个跟 top 命令比较类似,直接这样子输出。。。太可怕了,必须要用它自带的输出日志的方法
    xuboying
        5
    xuboying  
       2016-04-08 22:02:24 +08:00
    @phttc 必须要用这个程序么,
    统计流量也能用 iptables 啊 sudo iptables -L -t nat -v
    ...
    Chain POSTROUTING (policy ACCEPT 4441 packets, 299K bytes)
    pkts bytes target prot opt in out source destination
    30517 1963K MASQUERADE all -- any eth0 anywhere anywhere

    统计流速可以用 sar
    vonsis
        6
    vonsis  
       2017-02-03 08:24:46 +08:00
    configuration 里的 timers ,
    logging interval 默认是 60 分钟,所以你开监控,跑去看 log ,空的,再看,还是空的
    等一小时再去看,或者修改一下这个值为 1 分钟。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1772 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:35 · PVG 00:35 · LAX 09:35 · JFK 12:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.