开发者社区 问答 正文

Linux 下有什么可以按照用户(或进程)来统计流量的方法么?

我是指按照 Linux 进程所归属的用户为单位来统计流量。
最好是在 /proc 或者 /sys 里的哪个文件里可以找到以进程为单位的流量统计信息。

展开
收起
a123456678 2016-06-17 16:09:19 2291 分享 版权
1 条回答
写回答
取消 提交回答
  • 使用 iptables, 按照进程所属用户匹配从本地流出的包:

    iptables -I OUTPUT -m owner --uid-owner www-data
    然后即可在 iptables 中看到统计信息:

    iptables -L -v
    效果:

    Chain OUTPUT (policy ACCEPT 1277 packets, 484K bytes)
    pkts bytes target prot opt in out source destination
    277K 431M all -- any any anywhere anywhere owner UID match www-data

    2019-07-17 19:42:59
    赞同 展开评论