Monitor Synology disk temperature from SNMP

I’m always looking at how to get informations from my I.T. systems ; although it often ends they do nothing…

Here’s a trick to monitor the disks temperature of a Synology NAS (DS409slim in my case).

Enable monitoring on the Synology

First of all, we’ll need the smartmontools. If you don’t already have it, install it using ipkg:

# ipkg install smartmontools # which smartctl /usr/syno/bin/smartctl

Once done, let’s try to find the devices:

# smartctl --scan /dev/hda -d ata # /dev/hda, ATA device /dev/hdb -d ata # /dev/hdb, ATA device /dev/hdc -d ata # /dev/hdc, ATA device /dev/hdd -d ata # /dev/hdd, ATA device (...) /dev/sda -d scsi # /dev/sda, SCSI device /dev/sdb -d scsi # /dev/sdb, SCSI device /dev/sdc -d scsi # /dev/sdc, SCSI device /dev/sdd -d scsi # /dev/sdd, SCSI device (...)

I don’t know why it lists both ATA and SCSI disks… Maybe because I have SATA disks… Anyway, let’s see if the disk answers to information requests:

# smartctl -a /dev/hda -d ata | egrep "Model|Temp" Model Family: Toshiba 2.5" HDD MK..59GSM (Adv. Format) Device Model: TOSHIBA MK1059GSM 194 Temperature_Celsius 0x0022 100 100 000 Old_age Always - 32 (Min/Max 20/46)

So we can get the information from every of the disks installed.

Now, let’s extend the SNMP daemon so that it prints disks temperature when polled:

# vi /usr/syno/etc/snmpd.conf (...) #extend disktemp /opt/bin/bash -c "/opt/bin/find /dev/sd[a-z] -exec /usr/syno/bin/smartctl -iA -d ata {} \\; | /opt/bin/awk ' /Serial Number:/ { printf \"%s: \", \$NF }; /Temperature_Celsius/ { print \$10 }; ' | /opt/bin/sed -e \"s/[-_]//g\"" # /usr/syno/etc/rc.d/ restart

From a remote machine, we can now get the results:

# snmpget -v 2c -c public syno 'NET-SNMP-EXTEND-MIB::nsExtendResult."disktemp"' NET-SNMP-EXTEND-MIB::nsExtendResult."disktemp" = INTEGER: 0 # snmpwalk -v 2c -c public syno 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp"' NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp".1 = STRING: Y0DHF8LPS: 31 NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp".2 = STRING: Y0DHF8KTS: 30 NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp".3 = STRING: 90L3P2GFT: 31 NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp".4 = STRING: WDWXN209NC0986: 35

That’s it! The information can now be grabbed, stored and graphed from you preferred monitoring tools.

What you see is what you get

Here’re two examples of what I achieved using both “Munin” and “Xymon”. It only requires writing the scripts that will poll the snmp daemon and put the values into the correct format.

You can probably do the same with Nagios, Cacti, … but I don’t use those.

Improving response time

If you’ve had a detailed look at the graphs, you may have noticed that there are holes in the graphs. This is (AFAIK) because the snmpd of the syno answers in between 1.7 and 3 seconds. When it takes too long to answer, Munin and Xymon seem to not write the data in their RRDs.

Therefor, I have modified the way the data are published. From the synology:

# touch /tmp/disktemp.log # cat /usr/syno/etc/snmpd.conf (...) extend disktemp /opt/bin/cat /tmp/disktemp.log # /usr/syno/etc/rc.d/ restart # cat /etc/crontab (...) */5 * * * * root ( /opt/bin/find /dev/sd[a-d] -exec /usr/syno/bin/smartctl -iA -d ata {} \; | /opt/bin/awk ' /Serial Number:/ { printf "%s: ", $NF }; /Temperature_Celsius/ { print $10 }; ' | /opt/bin/sed -e "s/[-_]//g" ) > /tmp/disktemp.log # /usr/syno/etc/rc.d/ stop stop crond # /usr/syno/etc/rc.d/ start Starting crond...

Here’s the time response comparison:

snmpd only snmpd and crontab real 0m2.387s 0m0.012s user 0m0.008s 0m0.008s sys 0m0.004s 0m0.004s

So far, I get no holes anymore. If the poll was to be done faster, one may change the crontab to generate the file oftener.


Initial idea was stolen from there: Monitoring de la température des “disk” de Nexenta en SNMP

Unfortunately, my virtual Nexenta with Raw Device Mapping can get the SMART informations :-/


Author: Joel Carnat

@work Technical Architect and SysAdmin ; @home OpenBSD and FOSS, Karate, Kobudō, Jōdō, Bodyweight workout, Photography & Music

8 thoughts on “Monitor Synology disk temperature from SNMP”

  1. This looks exactly what I need but I am not able to execute your scripts. Can you explain what you are doing? I do not have /opt/bin/awk, /opt/bin/sed /opt/bin/find, etc. which ipkg packages do I need to install to get these?

  2. Wher I’m using command from ash:
    /opt/bin/bash -c “/usr/bin/find /dev/sd[a-z] -exec /usr/syno/bin/smartctl -iA -d ata {} \\; | /usr/bin/awk ‘ /Serial Number:/ { printf \”%s: \”, \$NF }; /Temperature_Celsius/ { print \$10 }; ‘ | /bin/sed -e \”s/[-_]//g\””

    is OK. But when I’m trying to execute snmpwalk from remote host I’m getting :NET-SNMP-EXTEND-MIB::nsExtendNumEntries.0 = INTEGER: 1
    NET-SNMP-EXTEND-MIB::nsExtendCommand.”disktemp” = STRING: /opt/bin/bash
    NET-SNMP-EXTEND-MIB::nsExtendArgs.”disktemp” = STRING: -c “/usr/bin/find /dev/sd[a-z] -exec /usr/syno/bin/smartctl -iA -d ata {} \\; |
    NET-SNMP-EXTEND-MIB::nsExtendInput.”disktemp” = STRING:
    NET-SNMP-EXTEND-MIB::nsExtendCacheTime.”disktemp” = INTEGER: 5
    NET-SNMP-EXTEND-MIB::nsExtendExecType.”disktemp” = INTEGER: exec(1)
    NET-SNMP-EXTEND-MIB::nsExtendRunType.”disktemp” = INTEGER: run-on-read(1)
    NET-SNMP-EXTEND-MIB::nsExtendStorage.”disktemp” = INTEGER: permanent(4)
    NET-SNMP-EXTEND-MIB::nsExtendStatus.”disktemp” = INTEGER: active(1)
    NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.”disktemp” = STRING: /opt/bin/bash: -c: line 1: syntax error: unexpected end of file
    NET-SNMP-EXTEND-MIB::nsExtendOutputFull.”disktemp” = STRING: /opt/bin/bash: -c: line 1: syntax error: unexpected end of file
    NET-SNMP-EXTEND-MIB::nsExtendOutNumLines.”disktemp” = INTEGER: 1
    NET-SNMP-EXTEND-MIB::nsExtendResult.”disktemp” = INTEGER: 2
    NET-SNMP-EXTEND-MIB::nsExtendOutLine.”disktemp”.1 = STRING: /opt/bin/bash: -c: line 1: syntax error: unexpected end of file

    SNMP configuration is as you worte in article, but path to find, sed and awk are corrected . My system is : GNU/Linux synology_ppc853x_210+

    Could you give me a some hints, please?

    1. Well, the syntax error is probably a ‘, ” or \ that is parsed differently from shell and from snmpd.
      Could also be carriage return in the snmpd.conf

      Have a look at the #3 “Improving response time” section. More than improving the response time, you only have to copy/paste shell command from shell to cron. Which makes very easy maintenance.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.