File: hxnetload

package info (click to toggle)
hxtools 20251011-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,468 kB
  • sloc: ansic: 4,384; perl: 3,467; sh: 1,664; cpp: 353; makefile: 90
file content (49 lines) | stat: -rwxr-xr-x 1,253 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# SPDX-License-Identifier: MIT
#
#	netload
#	written by Jan Engelhardt, 2002-2007
#
# NOTE: This script uses /proc/net/dev. Note that TX counters are NOT updated
# for vmnet-bridge traffic!
COMPAT_PROC="" # FreeBSD:/compat/linux

if [ -z "$1" ]; then
	echo "Usage: $0 <device> [interval]";
	exit 1;
fi

if [ -z "$2" ]; then
	sleeper=sleep;
	wait=1;
elif [ "$2" -ge 50000 ]; then
	sleeper=usleep;
	wait="$2";
else
	sleeper=sleep;
	wait="$2";
fi;

while :; do
	cat "$COMPAT_PROC/proc/net/dev" | grep " $1" | cut -f 2 -d:;
	"$sleeper" $wait;
done | perl -pe '$|=1;s/.*://' | while read rxcnt rxpkt c d e f g h txcnt txpkt; do
	if [ "$all" != "" ]; then
		now="`cat "$COMPAT_PROC/proc/uptime" | cut -f 1 -d " " | sed s/"\."//g`";
		[ $[$now-$oldtm] -eq 0 ] && continue;
		rxbytes=$[($rxcnt-$oldrx)*100/($now-$oldtm)];
		rxint=$[$rxbytes/1024];
		rxfrac=$[$rxbytes-($rxbytes/1024*1024)];

		txbytes=$[($txcnt-$oldtx)*100/($now-$oldtm)];
		txint=$[$txbytes/1024];
		txfrac=$[$txbytes-($txbytes/1024*1024)];

		printf "\r\e[2K""  IN: %9d.%03d KB/s    OUT: %9d.%03d KB/s" \
			$rxint $rxfrac $txint $txfrac;
	fi;
	all=$[$rxcnt+$txcnt];
	oldrx=$rxcnt;
	oldtx=$txcnt;
	oldtm="`cat "$COMPAT_PROC/proc/uptime" | cut -f 1 -d " " | sed s/"\."//g`";
done;