IoT - IT Hardware Monitoring with Node-Red
I run Linux here...
This means that most of my instructions will be Linux-based. But, If I work out how to do things under Windows or Mac, I'll try to write those up as well.
Contents
Getting the information from the hardware
Sensor data
lm-sensors 3.6.0 does JSON output (w00t w00t)
Mosquitto can be given the JSON output from lm-sensors
(This may be just a little TOO easy... :P )
/usr/bin/mosquitto_pub -h automation.DOMAIN.TLD -t MachineName -m "`/usr/local/bin/sensors -j`"
This, of course, can be run by cron. On my machines, I've told cron to run it once per minute.
Other data
Pretty much anything you can persuade your machine to spit out as plain text can be turned into MQTT messages using your scripting language of choice. (or even get hard-core & write some full-on code.)
The /proc
filesystem is an excellent source of system information. (One heck of a rabbithole to dive down can be found by typing man proc
into a terminal.)
I have a little script on my machines to spit out stats. It formats the output as JSON to be transferred via MQTT. The following scripts spit out individual parts. My script (WIP) is a combination of them all.
uptime
1 # Get uptime
2 if [ -f "/proc/uptime" ]; then
3 uptime=`cat /proc/uptime`
4 uptime=${uptime%%.*}
5 seconds=$(( uptime%60 ))
6 minutes=$(( uptime/60%60 ))
7 hours=$(( uptime/60/60%24 ))
8 days=$(( uptime/60/60/24 ))
9 fi
10
11 printf '{\n\t"uptime":"%s:%s:%s:%s",\n}\n' "$days" "$hours" "$minutes" "$seconds"
Load Averages
Still working on this one...
1 # Get loadavg
2 if [ -f "/proc/loadavg" ]; then
3 loadavg=`cat /proc/loadavg`
4 #loadavg=${loadavg%%.*}
5 fi
6
7 # Place holder data
8 OneMin="0.00"
9 FiveMin="0.00"
10 FifteenMin="0.00"
11
12 printf '{\n\t"loadavg":"%s %s %s"\n}\n' "$OneMin" "$FiveMin" "$FifteenMin"
Dealing with the information in Node-Red