4 ms·
Addendum: 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 term
by btschaegg 6y ago
Addendum: 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