In addition to the very succesful 'How to monitor your internet connection with virtual custom sensors' (see: viewtopic.php?f=21&t=13814)
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 smartmontools2. 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 ssdhealth2domo.sh) with:
Code: Select all
#!/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"
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 ssdhealth2domo.shCode: Select all
crontab -eCode: Select all
@daily sudo /usr/sbin/smartctl -t long /dev/sda
@daily /path/to/script/ssdhealth2domo.shThe second line sends the value to domoticz
If setup correctly, domoticz will receive your results from smartmontools daily:
And you can do 'useful' stuff with it
Notes:
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
Enjoy!