User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

CPU temperature graphs

Fri May 05, 2017 7:47 pm

For years I have been collecting data about my raspberry pi's cpu temperature with the objective to do something nice with it one day. Today appears to be that day! Recently I looked around for a decent graphing solution for my greenhouse and I ended up with Google Graphs. Immediately I realized this was a suitable solution for RPi tempmon as well.
This is how the result looks:
Image
Prerequisites for this project:
-You have one or more networked Pi's running more or less 24/7.
-All of these must be equipped to log their temperature as described in: https://www.raspberrypi.org/learning/temperature-log/
-A common file share where all machines can dump their data. I'm using NFS.
-NTP time sync, just to have some consistency in your data.
-A web server with cgi scripting enabled. I'm using lighttpd but Apache will also work.
-Some cronjobs and a few scripts, I have written them in Perl. :idea:
Contrary to Python, Perl comes pre-installed with the image and it has been the system admin language of choice for years. As far as I'm concerned it still is. 8-)

The data I gathered consists of an hourly recording of the temperature together with a timestamp. Thus far I kept this data in plain txt files in a .csv-like format but as part of the project I migrated all data to an sqlite database; it could also have been MySQL but -at least in my opinion- sqlite is the most lightweight, stable and resource-friendly solution for low-end platforms like the Pi.

The reason I'm posting this is that there might be others who want to build something similar, it is a nice little weekend project.
I'm attaching a zip with all relevant files but of course you will need to do a bit of customizing.
This is mostly related to entering your own pi's in the code.
The way I used google graphs is a bit of a dirty hack; I've copied the first section of html code to a file which is printed to the web by the .cgi script. After this, the script outputs the formatted data to display the temperatures and subsequently I have a trailer which contains the final part of the html code. You can customize the page by editing the html data. Admittedly dirty but in lieu of a java client to query the sqlite DB, this was the best I could do. For now it works like a charm and if anyone has a better solution, I'm open to it!
This is not a dead-simple project but if you already have multiple pi's in a network this should be feasible.
Alternatively you can do it in two stages. First set up the logging to sqlite and then program the cgi scripts to display the data.
I'm prepared to answer questions but if you decide to have a go at this I do expect a certain level of determination.

/emgi
Attachments
templogger.zip
(4.03 KiB) Downloaded 161 times

Return to “Other programming languages”