IoT - IT Hardware Monitoring with Node-Red

From The TinkerNet Wiki
Revision as of 13:05, 11 October 2020 by Tinker (talk | contribs) (→‎Other data)
Jump to navigation Jump to search

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.

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.)

I have a little script on my machines to spit out stats. It formats the output as JSON to be transferred via MQTT.

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...

Dealing with the information in Node-Red