我目前正在观察我的服务器上的一些进程,并想看看它有多少带宽总共使用了自从它开始以来。我不想知道它当前的用法,nethogs
/也对nload
我没有帮助。
答案1
看我的在这里回答。
您可以使用 nethog 来监控每 MB 的总带宽,因为它开始于:
sudo nethogs -v 3
答案2
有趣的问题。看来您至少可以看到 IP6 进程的 snmp 值/proc/[pid]/net/dev_snmp6/[DEV]
:
ifIndex 4
Ip6InReceives 4
Ip6InHdrErrors 0
Ip6InTooBigErrors 0
Ip6InNoRoutes 0
Ip6InAddrErrors 0
Ip6InUnknownProtos 0
Ip6InTruncatedPkts 0
Ip6InDiscards 0
Ip6InDelivers 4
Ip6OutForwDatagrams 0
Ip6OutRequests 24
Ip6OutDiscards 0
Ip6OutNoRoutes 0
Ip6ReasmTimeout 0
Ip6ReasmReqds 0
Ip6ReasmOKs 0
Ip6ReasmFails 0
Ip6FragOKs 0
Ip6FragFails 0
Ip6FragCreates 0
Ip6InMcastPkts 2
Ip6OutMcastPkts 34
Ip6InOctets 618
Ip6OutOctets 1946
Ip6InMcastOctets 304
Ip6OutMcastOctets 2786
Ip6InBcastOctets 0
Ip6OutBcastOctets 0
Ip6InNoECTPkts 4
Ip6InECT1Pkts 0
Ip6InECT0Pkts 0
Ip6InCEPkts 0
Icmp6InMsgs 2
Icmp6InErrors 0
Icmp6OutMsgs 22
Icmp6OutErrors 0
Icmp6InCsumErrors 0
Icmp6InDestUnreachs 0
Icmp6InPktTooBigs 0
Icmp6InTimeExcds 0
Icmp6InParmProblems 0
Icmp6InEchos 0
Icmp6InEchoReplies 0
Icmp6InGroupMembQueries 0
Icmp6InGroupMembResponses 0
Icmp6InGroupMembReductions 0
Icmp6InRouterSolicits 0
Icmp6InRouterAdvertisements 2
Icmp6InNeighborSolicits 0
Icmp6InNeighborAdvertisements 0
Icmp6InRedirects 0
Icmp6InMLDv2Reports 0
Icmp6OutDestUnreachs 0
Icmp6OutPktTooBigs 0
Icmp6OutTimeExcds 0
Icmp6OutParmProblems 0
Icmp6OutEchos 0
Icmp6OutEchoReplies 0
Icmp6OutGroupMembQueries 0
Icmp6OutGroupMembResponses 0
Icmp6OutGroupMembReductions 0
Icmp6OutRouterSolicits 9
Icmp6OutRouterAdvertisements 0
Icmp6OutNeighborSolicits 3
Icmp6OutNeighborAdvertisements 0
Icmp6OutRedirects 0
Icmp6OutMLDv2Reports 10
Icmp6InType134 2
Icmp6OutType133 9
Icmp6OutType135 3
Icmp6OutType143 10
但这很可能是我最终编译的一个特殊的内核功能。
cat /proc/3553/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
eth0: 23650521 158896 0 0 0 0 0 9457 720802 4696 0 0 0 0 0 0
lo: 53621 490 0 0 0 0 0 0 53621 490 0 0 0 0 0 0
通过查询net/dev
中的文件/proc/[pid]
。您可以读取每个使用的接口的 IO 字节。
带宽需要除以进程的正常运行时间,可以通过 找到clock(3)
。但可能还有其他方法来查找进程的开始时间。
在我看来,这stat /proc/[pid]
可能非常准确,并且还/proc/[pid]/stat
包含自系统启动以来的时钟滴答时间。