File: hxnetload

package info (click to toggle)
hxtools 20201116-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,696 kB
  • sloc: ansic: 5,074; perl: 3,589; cpp: 2,152; sh: 1,610; asm: 173; makefile: 153
file content (52 lines) | stat: -rwxr-xr-x 1,314 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
50
51
52
#!/bin/bash
#
#	netload
#	written by Jan Engelhardt, 2002-2007
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the WTF Public License version 2 or
#	(at your option) any later version.
#
# NOTE: This script uses /proc/net/dev. Note that TX counters are NOT updated
# for vmnet-bridge traffic!
#

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 /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 /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 /proc/uptime | cut -f 1 -d " " | sed s/"\."//g`";
done;