Thought I would post this here as I was able to use this thread to get some temperature reporting graph set up and I know others had asked for it so I thought I would share my setup as it might benefit others. Show no mercy I can take it but know this was my first attempt at javascript.
The idea is that I use a modified version of the SMART reporting script in the OP.
The email that is generated then gets handled by a google script and dumped into a google spreadsheet.
When I want to see how my drives have been doing I just open the spreadsheet and look at the graph.
Here is what I see when I open my spreadsheet:
You might notice the data in my spreadsheet is a bit janky... this is purely due to my crap coding maybe someone who likes this can help me out.
Okay here is the script I modified from the OP put on my server and run every 15 mins with a cron job:
Code:
#!/bin/sh
### Parameters ###
drives="ada0 ada1 ada2 ada3 ada4 ada5"
email="******@gmail.com"
subject="hddtemps"
logfile="hddtempreport.tmp"
### Set email headers ###
(
echo "To: ${email}"
echo "Subject: ${subject}"
echo "Content-Type: text/html"
echo "MIME-Version: 1.0"
echo -e "\r\n"
) > ${logfile}
### Set email body ###
(
date "+%m-%d %H:%M:%S"
for drive in $drives
do
temp="$(smartctl -A /dev/${drive} | grep "Temperature_Celsius" | awk '{print $10}')"
echo -n ", "
echo -n "$temp"
done
echo ""
) >> ${logfile}
### Send report ###
sendmail -t < ${logfile}
### rm ${logfile} ###
This is an example of the logfile that is generated and emailed:
To:******@gmail.com
Subject: hddtemps
Content-Type: text/html
MIME-Version: 1.0
03-16 21:03:34, 36, 35, 37, 32, 33, 31
With my gmail I set up a label based on that subject line. The label will hold all the emails for me and I could turn the notifications of those emails down to once a week. This way I don't even see that I am getting these emails every 15 minutes. It might be possible to turn the notifications of that label all the way off but I haven't figured out how yet. These emails stay unread in that label which is important for the next piece.
Here is my script that I have on google scripts. I set it to automatically run every 6 hours or so:
Code:
function hddtempsmailtosheet() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/*************************************/edit');
var label = GmailApp.getUserLabelByName("hddtemps");
var unread = label.getUnreadCount();
if (unread > 0)
{
var threads = label.getThreads(0,unread);
for (var i = threads.length -1; i>=0; i--) {
var messages = threads.getMessages();
for (var j = 0; j < messages.length; j++) {
var temps = messages[j].getBody();
var array = temps.split(',');
var sheet = ss.getSheets()[0];
sheet.appendRow([array[0], array[1], array[2], array[3], array[4], array[5], array[6]]);
messages[j].moveToTrash();
}}}
}
Okay so yeah that is my first javascript using a bunch of the examples in the google help docs. This took forever even though for most of you all this is probably pretty straightforward. As is it though it still doesn't work quite right.
The idea is that every 6 hours the script runs and goes through my email with the hddtemps label and sucks up all the email data and puts it in an array and parses it and then feeds it to that spreadsheet (see image at top of post) and deletes the emails. I had to manually create the spreadsheet and copy the link over and grant all the permissions for the script to see my email and my spreadsheet. Obviously the script didn't generate the graph although that does seem possible with the google scripting. I made the graph once initially and then all the new data gets added automatically.
So yeah a semi-automatic setup to create a drive temperature graph!
The problems are numerous and include:
That my email script is built only for my particular set up of drives.
The google script has the same problem where the appendrow command is tied to my setup.
My Google script does this weird thing where is also sends the un-parsed emails to the spreadsheet(See the bottom of the screenshot). These end up being duplicated and I am not losing any data however this is super annoying and could lead to another problem if I wasn't going in every other day or so and deleting out all these unneeded lines from the spreadsheet.
Another potential problem is that google will only let spreadsheets get so big. I am not certain if it is based on total number of rows or total number of cells. It seems like it would be easy to create a script that would delete out a certain number of rows from the spreadsheet before adding new data in.
I initially built this for every 15 minutes because I was really trying to track the temps because I kept creeping over 40C. on a couple of my drives. This is just the graph from the restart of my server with the new airflow I have a huge spreadsheet I just made a copy of that has about 2 weeks of data. I just did a different airflow layout in my case and so I will continue to monitor this at that frequency and then hopefully I can reduce the frequency.
Hope this helps someone as I spent a lot of time on it. And if you have any tips on my scripts then would be much appreciated.