Tag Archives: smartmontools

How to monitor your diskhealth with domoticz’s virtual percentage sensors

preface

I was wondering how much I wore down my SSD after a few years of heavy domoticz usage. I really like the graphing functionality of domoticz to keep track of stuff and I have implemented a script that notifies me with Telegram when interesting stuff happens, so I wanted to monitor my disk health with domoticz, thought I’d share.

prerequisites

Install smartmontools

sudo apt-get install smartmontools

2. Create 1 [u]Virtual Sensor of the type ‘Percentage'[/u] (for SSD Health-value) and remember the idx (you need that later on) in Domoticz.

code

Create a script (Let’s call it ssdhealth2domo.sh) with:

#!/bin/bash
#setup
host=xxx.xxx.xxx.xxx
port=xxxx
username=xxx
password=xxx
ssdhealthidx=xxx
# no need to edit
ssdhealth=$(sudo smartctl --all /dev/sda | grep Wear_Leveling_Count | awk '{print $4}')
#output if you run it manually
echo "SSD Health = $ssdhealth%"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$ssdhealthidx&svalue=$ssdhealth"

I ‘grep’ the Wear_Leveling_Count out of the test-results-table because this gives me the best indication of wear-and-tear of my disk (Samsung) after what I have read. Some manufacturers use ‘one of the other’ indicators, so do some reading on what is the best indicator for your type of disk.

Don’t forget to make it executable (I always do … ):

chmod +x ssdhealth2domo.sh

And add the stuff to the crontab:

@daily sudo /usr/sbin/smartctl -t long /dev/sda
@daily /path/to/script/ssdhealth2domo.sh

smartctl now does a daily ‘long’ test on your /dev/sda disk at midnight. Because this is spawned to the background and ‘takes a while’ (in my case about 20 minutes) the second line in crontab will probably send the test-results from ‘yesterday’ to domoticz. But hey, better safe & late than sorry & never right ;)

result

If setup correctly, domoticz will receive your disk-health daily, so when it breaks you might be there in time to replace it without loss of data (no guarantees from me ofcourse :) )

screen-shot-2016-11-29-at-22-51-31