We were just talking about getting system info into graphs in the comments in a previous blog entry – and I realised I already had some code for getting that info in Python – and using a library that can provide a LOT more.
So – as it was there already - I thought I’d put this quick entry together for anyone interested.
There are a couple of nodes available for Node-Red but one of the things that I noticed was absent – someone is SURE to prove me wrong – was processor temperature. One use for that might be "let's graph this intensive scrip with and without using a fan"
But I already have that, I use it in a little Python script in a macro called “cls” – which when typed at the command line, gives me a clear screen with some useful info.
So – 15 minutes later, a VERY shoddily modified script – the thing that took the most time was using the PRINT statement while bearing in mind changes to PRINT from Python 2 to 3 as I’ve no idea which version you are using. Hence the long ugly line – but hey, it works – only tested in Python 2.7
So – here is the Node-Red…
The blue INJECT could inject anything in the payload – how about “hello” at timed intervals – say every minute or every 5 minutes… ok the EXEC node has to call the Python script and that takes a tiny fraction of a second and what a waste.. but if you’re only doing that once a minute – who cares.
The brown EXEC node has this…
The yellow (ish) FUNCTION node has this…
and for now the output is an object going to a debug node (green) – but of course it could just as easily be going to… say, Grafana.
And that’s it – here’s the Python script… I’ve left some stuff in there from my INFO.PY but typically anyone using this is going to want to add their own stuff so feel free to add in or strip out anything you like. You can of course test the script on the command line and it will put out something like this..
pi@pihd1:/home/pi> sudo python info2.py
If you’re not familiar with objects… to get the temperature would be something like….
If you wanted to sent the temperature to the influxdb node for graphing, you might use something like this - sending the output straight into the influxdb node.
Hopefully you get the general idea. Here’s my script – works for me – change/add/delete for what you might want to see and don’t forget, python is indent-sensitive (reminder - there's a lot of stuff in there you can strip out).