4 ms·
As a simple solution, you could poll `/proc/<pid>/net/dev` and calculate it yourself (from the difference of the total received bytes between two polls). `neth
by btschaegg 6y ago
As a simple solution, you could poll `/proc/<pid>/net/dev` and calculate it yourself (from the difference of the total received bytes between two polls).
`nethogs` is also useful.
If you'd like to do something more specialized, you could build something with a couple of lines in `bpftrace`, but you'll have to put in more work there if you're not familiar with it.
The book "BPF Performance Tools" by Brendan Gregg is a good introduction there. Of course, for a simple overview, that would be way overkill, though :)
- btschaegg 6y agoAddendum: Since I'm somewhat bored, anyway :) I whipped up a simple shell script for the polling thing. Usage: ./traffic.sh <pid> Copy-pastable for your terminal (dollar signs signify your prompt, obviously): $ cat <<'EOF' > traffic.sh #!/usr/bin/env bash pid=$1 set -euo pipefail while true; do date +'Time: %H:%M:%S' sed '/:/!d' /proc/$pid/net/dev echo sleep 1 done \ | awk ' BEGIN { MB = 1024*1024.0; } /^Time/ || /^$/ { print $0; next; } seen[$1] { rx_mbps = ($2 - rx[$1]) / MB; tx_mbps = ($11 - tx[$1]) / MB; printf("%10s Rx: %8.1f MiB/s, Tx: %8.1f MiB/s\n", $1, rx_mbps, tx_mbps); } { seen[$1] = 1; rx[$1] = $2; tx[$1] = $11; } ' EOF $ chmod +x traffic.sh
- victor106 6y agoThank you. Very helpful