How to monitor your diskhealth with virtual percentage sensors

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.
Post Reply
User avatar
Posts: 460
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL

How to monitor your diskhealth with virtual percentage sensors

Post by safi78 » Wednesday 30 November 2016 0:00

Hi all,

In addition to the very succesful 'How to monitor your internet connection with virtual custom sensors' (see: viewtopic.php?f=21&t=13814) :lol:

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:

1. Install smartmontools

Code: Select all

sudo apt-get install smartmontools
smartmontools is a utility to monitor disk-health.

2. Create 1 Virtual Sensor of the type 'Percentage' (for SSD Health-value) and remember the idx (you need that later on)

3. Create a script (I called it with:

Code: Select all



# 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:[email protected]$host:$port/json.htm?type=command&param=udevice&idx=$ssdhealthidx&svalue=$ssdhealth"

and fill in all the details after #setup:
host = your domoticz server (e.g. localhost or 192.168.x.x)
port = your domoticz port (e.g. 8080)
username = your domoticz username
password = your domoticz password
ssdhealthidx = the idx of the virtual sensor for accepting the ssdhealth-value

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

Code: Select all

chmod +x
4. edit your crontab (I scheduled this @daily):

Code: Select all

crontab -e
And put in the command:

Code: Select all

@daily sudo /usr/sbin/smartctl -t long /dev/sda
@daily /path/to/script/
The first line tests your (in my case) /dev/sda daily
The second line sends the value to domoticz

If setup correctly, domoticz will receive your results from smartmontools daily:
Screen Shot 2016-11-29 at 22.51.31.png
Screen Shot 2016-11-29 at 22.51.31.png (67.26 KiB) Viewed 844 times
And you can do 'useful' stuff with it ;)

1. I use it for my SSD, but this can be used with all devices tested with smartmontools, adjust to your setup.
2. The data is not real-time. Smartmontools spawns it's tests to the background, so if you run the tests daily, it will actually finish well after midnight. The values actually sent to domoticz are probably from the test from 'yesterday'.
3. I use the 'Wear_Leveling_Count' because this is the most usefull on MY SSD. you're milage may vary with other manufacturers. (It could be you should grep one of the other values shown with "sudo smartctl --all /dev/sda" (again, /dev/sda is where MY disk 'lives'))
4. smartmontools runs as root. My user can sudo without password, so that works. Probably not the most pretty, but hey, it works ;) If you don't like that you can always 'cron it' for root. (sudo crontab -e)

Last edited by safi78 on Wednesday 30 November 2016 21:37, edited 1 time in total.
I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests