Hey, just a heads-up that this content is based on an automatically imported version from our old CMS. If the formatting isn’t perfect, I’m sorry about that.
Intel NUCs from two generations ago have a nice feature: a multicolor LED Ring and Power LED that you can control by software. I use an i5 9th gen NUC at home as my “Homeserver, IoT, whatever” device. I created a tiny script running as cron every minute to set the LED Color depending on the internet connection “quality”. I’m not really pulling data from the modem; for my purposes, it’s not necessary. I just want to have a quick solution to let others in my family at home see if there are any issues or not. You know the situation: Wife cannot open a certain internet page or something is loading very slowly. “What’s wrong with our internet?” Most of the time the answer is “Nothing - it’s not on our end,” but now I have a quick way to visualize if anything may be wrong.
Now the NUC LED shows the following status:
- GREEN: Everything is fine
- YELLOW: Still no critical error, but ping is higher than it should be
- PINK: Something is wrong, but still “working” somehow
- RED BLINKING: DNS Lookup errors, Packet loss, probably big impact
Instead of writing a complicated measurement script, I really just make it simple and stupid. I do several Ping Checks via well-known hosts and in addition several DNS Lookups. If a DNS Lookup fails, I just add some “time,” and by evaluating the overall time the check process needed, I set the status:
#!/bin/bash
# vi: set ft=sh :
echo "Color NUC Ring LED based on Internet Status..."
my_dns_check() {
echo -n -e "Checking DNS: " $dnslookup
nslookup $dnslookup > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
echo -e " (DNS OK)"
else
echo -e " (DNS NACK)"
sleep 2.2
fi
}
start=`date +%s.%N`
result=$(fping -u -c1 192.168.200.1 4.2.2.4 1.1.1.1 9.9.9.9 denic.de google.com | grep -c ".")
dnslookup=a.root-servers.net;my_dns_check
dnslookup=cloudflare.com;my_dns_check
dnslookup=google.com;my_dns_check
dnslookup=amazon.de;my_dns_check
dnslookup=netflix.com;my_dns_check
dnslookup=spotify.com;my_dns_check
end=`date +%s.%N`
runtime=$( echo "$end - $start" | bc -l )
echo "Time needed:" $runtime
if (( $(echo "$runtime < 1" |bc -l) )); then
echo 'ring,3,none,green' | sudo tee /proc/acpi/nuc_led > /dev/null
elif (( $(echo "$runtime < 2" |bc -l) )); then
echo 'ring,5,none,yellow' | sudo tee /proc/acpi/nuc_led > /dev/null
elif (( $(echo "$runtime < 3" |bc -l) )); then
echo 'ring,10,fade_medium,yellow' | sudo tee /proc/acpi/nuc_led > /dev/null
elif (( $(echo "$runtime < 5" |bc -l) )); then
echo 'ring,20,none,pink' | sudo tee /proc/acpi/nuc_led > /dev/null
elif (( $(echo "$runtime >= 5" |bc -l) )); then
echo 'ring,60,blink_fast,red' | sudo tee /proc/acpi/nuc_led > /dev/null
sync
fi
To set the NUC LED Color, you need to install a module:
This is a simple kernel module to control the power and ring LEDs on Intel NUC7i[x]BN and NUC6CAY kits.