Hard Drive Temperature Monitoring using Smartctl and RRDTool on Buffalo Linkstation Quad Pro NAS

All the 4 disks in my Buffalo linkstation quad pro runs 24/7 and I am therefore particularly concerned about the temperature of the hard drives. The summer temperature here can be quite high and if I can identify that heat is a problem for the NAS, I will need to figure out a solution to cool down the NAS.

In order to know if heat is a problem, first I have to find a way to monitor the temperature of the hard drives. Fortunately most drives nowadays are S.M.A.R.T. supported. This article describes the steps I took to configure smartctl and rrdtool on my linkstation quad pro.

Smartctl is used to poll the hard drives for their temperature readings and rrdtool is used to collect the data and present them in a nifty graphical format.

First, some good background information.

  1. http://martybugs.net/linux/hddtemp.cgi
  2. http://ikeke.free.fr/syno/

The article by Martin Pot (the first link above) is a particularly good article as that forms the basis of what I am doing here, with some modifications of my own. Martin’s article is a must read for any rrdtool users.

First thing to do is to install rrdtool. This is simple enough. SSH into the NAS.

# ipkg install rrdtool

Now we need to make sure smartctl is working on the NAS.

# smartcl -A -d marvell /dev/sda

The output should at least look similar to this:

Note the line ID#194 which gives the temperature of the hard drive in celsius. In this case, disk 1 of the NAS (/dev/sda) is 38 deg. C right now.

Now we need to filter the output from smartctl such that we only return the actual temperature reading and ignore the rest of the output.

This is best done using the grep and awk command as follows (credit given to many posters in this forum thread):

# smartctl -A -d marvell /dev/sda | grep 194 | cut -d: -f3 | awk ‘{print $10}’

So the output on my screen now looks like this (note that I run the above command for each of the hard drives in the NAS): Note that /dev/sda refers to disk1, /dev/sdb refers to disk 2, and so on.

We are now moving in the right direction. We now need to log these info using rrdtool.

For this step, I rely heavily on the excellent works by Martin Pot. If you have not read his article earlier, read this now. But since our platforms are slightly different, I have to improvise his methods to suit my operating environment.

First, I downloaded his rrd_hddtemp.pl perl script. Then I winSCP this file to the NAS and save this to the directory /opt/bin. Make sure this file has a file extension .pl and not .txt. Rename accordingly.

Now SSH into the NAS box, cd to /opt/bin. Make this perl script executable by chmod the file.

# chmod 755 rrd_hddtemp.pl

Now we need to edit the file

# nano rrd_hddtemp.pl

The original rrd_hddtemp file provided by Martin Pot is tailored made for the linux PC platform but I am not able to get this to run on the NAS without some heavy modifications. Maybe my scripting skill is just too poor. The final version of this file after modifications can be downloaded here:

Joseph Lo’s version of rrd_hddtemp

Note that I have named this file with an extension .doc (as I am unable to upload a .pl file in wordpress). WinSCP this file to the /opt/bin directory, rename it with the .pl extension and overwrite Martin’s version if you have to.

Note: If you bother to download this and managed to improve the script, please send me a copy of your script so I can post your version here. Due credit will be given.

Okay. So we now have the script modified. The next thing to do is to manually create the directories for rrdtool to store its database and graphs.

I chose to store rrd’s database files in /opt/var/lib directory. The rrd database will be located inside a separate rrd directory. Note that if you choose to store the database any place else, you will need to manually edit rdd_hddtemp.pl to reflect the correct path name.

# mkdir /opt/var/lib/rrd

Then we need to create the directory where rrdtool will store its html web images (graphs).

# mkdir /mnt/disk1/Web/rrd

Note that ‘Web’ is previously defined in the web server module when we configure the NAS. Again, this is hard coded into the rrd_hddtemp script. If your preference is something else, be sure to amend the rrd_hddtemp script accordingly.

Now that we have everything setup, it is time to test the script.

cd to /opt/bin directory

# rrd_hddtemp.pl

This should return something similar to the following:

If it does, that means the script is working. Now check under the directory /opt/var/lib/rrd. There should be 4 files in there – sda.rrd, sdb.rrd, sdc.rrd and sdd.rrd. Depending on how you modify the scripts and assigned the names to your hard drives, your output may be slightly different.

Finally check the /mnt/disk1/Web/htdocs/rrd directory. There should be a whole bunch of .png files in this directory, something that resembles sda-day.png, sda-month.png, sda-week.png, etc.

If both of these directories contain the type of files I just mentioned, the script is truly working. It works for me and I hope it works for you too.

The last thing we need is to configure the system to run the rrd_hddtemp script every 5 mins or so. Don’t overdo this by running the script every 1 minute interval. This will bog the system down unnecessarily.

Putting the script in crontab is very simple.

cd to /etc/cron/crontabs

# nano root

Put this line anywhere in this file

*/5 * * * * /opt/bin/rrd_hddtemp.pl

The amended file should look something like this. Note the line highlighted in red.

Save the file. Restart the cron service. Now I am sure if it is really necessary to restart cron but I did so anyway.

# /etc/init.d/crond restart

We are now done.

Wait for say 15mins, then in the web browser, browse to The screen should look something like this. This is the temperature profile of my fourth disk (/dev/sdd) in the NAS.

The last part of this exercise is to consolidate the graphs in a webpage to present the data in a meaningful way. This is very easy too. Create an empty html page with image links pointing to the various .png files. The rest should be self-explanatory.

I hope this article is useful in any way. Happy “NAS”ing.

Posted on April 26, 2011, in Buffalo Quad Pro NAS. Bookmark the permalink. 12 Comments.

  1. Thanks for these howtos Joseph, they have been a great help.

    I’m wondering if you can do a howto on setting up the LS as an rsync server.

  2. I am glad you like the howtos. The article on rsync server is under preparation as a draft, so watch this space 🙂

  3. Oh thanks that is good news, once I have rsync working on this beast I will be a happy man.

    One thing I should add… Using your HDD temp monitoring script, I only have the first drive bay populated. But the script is giving me temperatures for 4 drives (well, the same temperature for 4 drives). I’m sure its just some return val needs checking, its been a long time since I did any scripting language.

  4. Hi Stumo,

    Very simple really….assuming all other variables within my scripts are aligned with your own settings, all you have to do is to put a # sign in front of these lines:
    &ProcessHDD(“sdb”, “Seagate Barracuda Green 2TB (ST2000DL003) Disk 2”);
    &ProcessHDD(“sdc”, “Seagate Barracuda Green 2TB (ST2000DL003) Disk 3”);
    &ProcessHDD(“sdd”, “Seagate Barracuda Green 2TB (ST2000DL003) Disk 4”);
    thereby effectively making them as “comments” within the script.

    That’s about it. Try it and let me know if it works for you.


  5. One minor change,

    ‘Then we need to create the directory where rrdtool will store its html web images (graphs).

    # mkdir /mnt/disk1/Web/rrd

    That should be

    # mkdir /mnt/disk1/Web/htdocs/rrd

    Great site, really useful, thanks.



  6. Also I had to do

    /etc/init.d# ./cron.sh restart

    as the crond command gave me a no such file error – maybe I have something missing from my path (sbin)?

  7. Hmm, checking back this morning I find all my graphs are the same regardless of the time scale, e.g. sda daily looks identical to sda-weekly, monthly, yearly. I was expecting the scale to be different. Will this sort itself out as I get more data? Thanks, Paul.

  8. Hi Paul, It should work fine. As obviously u need more data to be displayed for the weekly, monthly and yearly graph. Unfortunately I have since disabled the hddtemp script running on the buffalo and I won’t be able to show u the graphs…

  9. Yes. U are absolutely right. Sorry for the mistake 🙂

  10. what i did was to manually start crond whenever i edited the content of the cron file. It appears to work fine for me.

  11. The graphs are all coming out as the same because for some reason “-s -1$_[1]” to pass “day” “week” etc to the rrdtool graph time range in the original martybugs script has been replaced with -S “$_[1]” which makes no sense according to the RRDtool documentation and so is probably ignored. Changing this back sets the graphs up correctly.

  12. If anyone is still using this or is having trouble getting it to work, head over to github https://github.com/cron410/rrd_hddtemp/ and have look at the branches. I only have a Linkstation to test with, so there is a corresponding branch for it. All modifications listed in the comments above have been added to all branches. Feel free to make a pull request if you have something to add.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: