I am currently watching some process on my server and want to see how much bandwidth it has used in total since it has been started. I don't want to know its current usage, nor does nethogs / nload help me.
Asked
Active
Viewed 3,310 times
10
Ciro Santilli OurBigBook.com
- 17,176
- 4
- 113
- 99
Flatron
- 403
- 1
- 5
- 12
2 Answers
8
See my answer here.
You can use nethog with total bandwidth monitored per MB since it started with:
sudo nethogs -v 3
Asme Just
- 193
- 1
- 6
3
Funny question. It seems you can see snmp values of a process in /proc/[pid]/net/dev_snmp6/[DEV] at least for IP6:
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
but quite likely that is a special kernel feature I eventually compiled in.
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
By querying the net/dev file in /proc/[pid]. You can read the IO bytes for each used interface.
The bandwidth needs to be divided by the uptime of the process, which can be found by clock(3). But there might be other methods to find the start time of the process.
It seems to me, that stat /proc/[pid] might be quite exact and also /proc/[pid]/stat contains the time in clock ticks since system start.
ikrabbe
- 2,155
- 12
- 20
-
Thanks for this answer. Unfortunately this is a little late now because we had to continue our work, killing the process. But I know this will be helpful some time. Seems to be quite tricky to do this though ;) Best advice would be to run some kind of network monitoring as a "default" on a Linux server right after installation. – Flatron Jun 22 '15 at 20:09
-
1The network monitoring is no problem. But it's hard get the network io for a process. I was astonished to find something for ipv6. Your best bet is to setup a virtual network for a process and monitor the virtual interface. – ikrabbe Jun 22 '15 at 20:15
-
Which values to look for here? Also, how can I find which ID to look for instead of "pid" ? – android developer Nov 26 '19 at 21:05