Synology DSM monitoring with Monit

    

Monit is small, monit is fast, monit is installed on each of my servers. Unfortunately, I couldn’t found a package for Synology DSM 6. Hopefully, DSM is based on Linux and Monit provides binaries. So let’s install, run and monitor DSM using Monit.

Install Monit

It is possible to install and configure Monit using SSH and a shell console. But… DSM is Web 2.0 and I wanted to do the things using the Web GUI only.

Go to the Monit download section and grab Monit for linux-x64.

Using File Station, upload the tarball to the directory you like and uncompress the archive. Rename the directory as you like.

Guess what, it’s done!

Configure Monit

Inside the “conf” directory, you’ll find the “monitrc” configuration file. Read the comments and configure as usual.

The most tricky part is to guess the real pathname for the directory where you installed monit. Look inside the Shared Folder dialog box to guess that path. In my case, I installed the “monit” directory in the “apps” shared folder on the “Volume 1” location. This gives the following full pathname: “/volume1/apps/monit”.

Make sure Monit is running

The simplest way to check if monit is running and, if not, to start it is to use the native “Task Scheduler”, from the “Control Panel”.

In the monit/bin directory, using the “Text Editor”, I wrote a small shell script, named check_monit.sh:

#!/bin/bash
#
# Check if Monit runs.
# If not, starts it
#

MONIT_DIR="/volume1/apps/monit"
MONIT_BIN="$MONIT_DIR/bin/monit"
MONIT_PID="$MONIT_DIR/monit.pid"
MONIT_CONF="$MONIT_DIR/conf/monitrc"

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

if [ -f "$MONIT_PID" ]; then
 PID=$(cat $MONIT_PID)
else
 PID=""
fi

FOUND=$(ps -aef | awk '{ print $2 }' | grep "^$PID$")

# If Monit wasn't found, set various permissions and start it. Else, just quit.
if [ -z "$FOUND" ]; then
 chmod 0600 "$MONIT_CONF"
 chmod 0755 "$MONIT_BIN"
 exec "$MONIT_BIN" -c "$MONIT_CONF"
fi

exit 0

Then I used the Task Scheduler to run this check every 5 minutes.

In the end, I ended with a classic Monit view of my Synology services.