It flashes the left LED "green" for disk activity, and the right LED "yellow" for network activity. It updates once per second. It cleans up, restoring the LEDs to green on exit. Run it at login, or configure as a service, for example: https://www.linode.com/docs/quick-answe ... e-at-boot/
It needs to run as root, in order to configure and write the gpios in /proc. But with a little system pre-configuration, that can be avoided. The script will check either way.
It's pretty simple and could be dressed up quite a lot. But, it works for my purposes. Enjoy!
[Updated to use only bash builtins, slightly more efficiently]
Code: Select all
#!/bin/bash
#
# Fitlet2 disk and network activity monitoring daemon
# flashes left LED green for disk, right LED yellow for net
#
init () {
cd /sys/class/gpio
if [ ! -w gpio435/value ]
then
# initialize gpio nodes, if not already prepared
if [ ! -w export ]
then
echo "cannot initialize gpios" 1>&2
exit 1
fi
for G in 435 436 437 438
do
echo $G > export
echo out > gpio$G/direction
done
fi
# lights out
for G in 435 436 437 438
do
echo 0 > gpio$G/value
done
# simple daemon mode
trap '' 1
trap 'fini' 2 3 15
exec 0</dev/null 1>/dev/null 2>&1
# fd 3 = left LED green (disk), fd 4 = right LED yellow (net)
exec 3>gpio435/value 4>gpio438/value
# fd 5 = fifo for sleeping via builtin read
mkfifo -m 0600 /tmp/fitlet2leds-fifo
exec 5<>/tmp/fitlet2leds-fifo
rm -f /tmp/fitlet2leds-fifo
INIT=1
}
fini () {
# restore green lights
echo 1 > gpio435/value
echo 0 > gpio436/value
echo 1 > gpio437/value
echo 0 > gpio438/value
exit 0
}
checkactive () {
ODSK=$DSK ; DSK=0
ONET=$NET ; NET=0
# tally all read+write to non-loop base block devices
while read MAJ MIN NAM F4 F5 RD F7 F8 F9 WR FOO
do
case $MIN in 0) ;; *) continue ;; esac
case $NAM in loop*) continue ;; esac
DSK=$((DSK+RD+WR))
done < /proc/diskstats
# tally all in+out IP octets to physical network devices
while read HDR F1 F2 F3 F4 F5 F6 IN OUT FOO
do
case $HDR in IpExt*) ;; *) continue ;; esac
case $F1 in [0-9]*) ;; *) continue ;; esac
NET=$((NET+IN+OUT))
done < /proc/net/netstat
}
while :
do
case $INIT in "") init ;; esac
case $((DSK - ODSK)) in 0) ;; *) echo 1 >&3 ;; esac
case $((NET - ONET)) in 0) ;; *) echo 1 >&4 ;; esac
read -t .25 -u 5
echo 0 >&3
echo 0 >&4
read -t .75 -u 5
checkactive
done &