Getting Scrutiny working with Synology DSM

It has been a while since I wrote anything up as I have been busy with other things, but I felt the need to write this one up because I was not able to find anything even close to helpful when I was setting it up.

Scrutiny is a Web UI that uses smartd to show you the state of your hard drives. Now I will not re-invent the wheel with getting it all set up as the creators docs on the GitHub repo are already very good, but Synology is not listed as supported.

In a nutshell, the issue with trying to run the collector on a Synology NAS is the version of smartd that Synology provides is v6.5, Scrutiny requires v7.x to work.

Add to that, there is no out of the box way to get it updated to the latest version. So here ill go through how to deploy the collector part of Scrutiny to a Synology NAS.

Let's Go!

Firstly we need to create a way to be able to install packages on DSM 7 (I have only tested this on DSM 7), The easiest way is Entware.

SSH into your Synology NAS and switch into root. I will list the commands here, but they can be found here on the Entware GitHub repo. (I was switched into the root user for the below, but if you are not then use sudo where required)

# 1. Create a folder on your hdd (outside rootfs)

mkdir -p /volume1/@Entware/opt

# 2. In my case i already had /opt and instead of using mount i just used a symlink

ln -s /volume1/@Entware/opt/ /opt

3. Run install script depending on the processor (I have a DS420J, other scripts can be found in the above link for Entware)

wget -O - https://bin.entware.net/aarch64-k3.10/installer/generic.sh | /bin/sh

Now reboot your NAS, when it comes back SSH back in.

# Run an update
opkg update

# Run an upgrade
opkg upgrade

# Install smartmontools
opkg install smartmontools

It should install v7.2-2
`Installing smartmontools (7.2-2) to root...`

That really is the trickiest part, Now let's get the collector set up

# 1. We will now create the directories.

mkdir -p /volume1/\@Entware/scrutiny/bin
mkdir -p /volume1/\@Entware/scrutiny/conf

# 2. change into the bin directory

cd /volume1/\@Entware/scrutiny/bin

# 3. Download the collector binary for your architecture and make it executable

wget https://github.com/AnalogJ/scrutiny/releases/download/v0.4.12/scrutiny-collector-metrics-linux-arm64

chmod +x /volume1/\@Entware/scrutiny/bin/scrutiny-collector-metrics-linux-arm64

# 4. Create a config file for the collector

cd /volume1/\@Entware/scrutiny/conf
wget https://raw.githubusercontent.com/AnalogJ/scrutiny/master/example.collector.yaml
mv example.collector.yaml collector.yaml

# 5. Lets make some changes in the config file, these ae what i uncommented/added

host:
  id: 'Server_Name'
  
 
devices:
#  # example for forcing device type detection for a single disk
 - device: /dev/sda
   type: 'sat'
 - device: /dev/sdb
   type: 'sat'
 - device: /dev/sdc
   type: 'sat'
 - device: /dev/sdd
   type: 'sat'
    
api:
 endpoint: 'http://<url>:8080'

(Please note that you may need to tweak the device type depending on what your HDD brand/model is. My WD Red Pro seem to only return valid data with sat)

So we have done all the prep, well ... some of it. That's the bulk of it. The next bits are updating the smartd DB and also setting up a scheduled task to run (every 6 hours)

So let's get this all wrapped up

# 1. Let's update the smartd db.

cd /volume1/\@Entware/scrutiny/bin/
wget https://raw.githubusercontent.com/smartmontools/smartmontools/master/smartmontools/drivedb.h

# 2. I ran it like this but you can tweak to your liking, the most important part is the --drivedb, as this loads it into the aplication for future use

smartctl -d sat --all /dev/sda  --drivedb=/volume1/\@Entware/scrutiny/bin/drivedb.h

# 3. Now lets create a small bash script, this will be used for the scheduled task inside Synology

vim /volume1/\@Entware/scrutiny/bin/run_collect.sh

# The contents are below, copy and paste them in

#!/bin/bash

/volume1/\@Entware/scrutiny/bin/scrutiny-collector-metrics-linux-arm64 run --config /volume1/\@Entware/scrutiny/config/collector.yaml

This is all set up from a backend point of view, now let's get Synology to run a scheduled task. Log in to DSM and do the following:

Goto: DSM > Control Panel > Task Scheduler

Create > Scheduled Task > User Defined Script

 General

Task: Scrutiny_Collector
User: root
Enabled: yes

 Schedule

Run on the following days: Daily

  Time:

 Task Settings

  Run Command

. /opt/etc/profile; /volume1/\@Entware/scrutiny/bin/run_collect.sh

If all has gone well, you can click OK and run the task to check the output.

Now every 6 hours the following will happen:

  1. Scheduled task runs as the given user calling the simple bash script we added earlier
  2. This bash script runs the collector with the tweaking config file
  3. The collector will use smartd installed via opkg which is version 7.x and has an updated smartd DB.
  4. The results will be pushed to the scrutiny API end point.

I hope this helps any Synology users wanting to deploy this.