DIY Projects

Monit: Monitoring your smarthome box (Domoticz, Jeedom…)

monit interface web home domoticz

Monit is a program that allows to monitor the functioning of a server and the critical programs. Monit will allow us to monitor the vital parameter of the computer or the Raspberry Pi. For example the CPU load is not too high, the available RAM is sufficient, etc… Monit is able to restart a service, for example to restart the Domoticz service and restart the computer (or the Raspberry Pi) after several consecutive failures.

For this tutorial, I used my box automation Domoticz installed on a Raspberry Pi 3. I follow this tutorial.

Install Monit

Monit is installed simply by using the command apt-get install . The installation takes a few minutes.

sudo apt-get install monit

Configure Monit

You configure Monit by using a configuration file monitrc which is located in the directory /etc/monit /. Open the configuration file with

 sudo nano/etc/monit/monitrc

Monitoring interval

You can set the frequency of monitoring (server, software…), delay the start of monitoring after start-up and the path to the log (log). Go to Global Section

A cycle (in the jargon of Monit) corresponds to a launch of the service.

Set up an email to send out notifications

Monit is able to send a notification by email in the event of a significant change or warning. Find the line “set mailserver You can send a notification email from Gmail or POP3 account. Edit the block according to your settings and copy in monitrc configuration file.

Sent from a Gmail account

If you are using 2-step Gmail verification, you must create a new app here

 set mailserver port 587 
 username "" password "MYPASSWORD"
 using tlsv1
 with timeout 30 seconds
 set alert

Ships from one account POP3

 set mailserver port 25
  with timeout 30 seconds
  set mail-format { from: }
  set alert

Set the Monit Web server

Monit has its own Web server. It is not active by default at installation time. It is necessary to enable it to monitor Domoticz. Guests also have access to a web interface which summarizes the activity of your box home automation. Find the section set httpd port 2812 and uncomment lines. You can very precisely manage the security of Monit.

set httpd port 2812 and
#   use address localhost  # only accept connection from localhost
   allow localhost        # allow localhost to connect to the server and
   allow admin:monit      # require user 'admin' with password 'monit'
   allow @monit           # allow users of group 'monit' to connect (rw)
   allow @users readonly  # allow users of group 'users' to connect readonly

The web interface will be available on port 2812 the domotics box. For example

If you don’t want that Web interface is available from another computer, uncomment the line use address localhost . Instead the line allow allows either to accept all positions or only the specified post. The first block of is its ip address, the second block for the mask of the network (for example,

You can set a user (here admin ) and his password (here monit).

Monitor Domoticz

This rule allows to monitor the Domoticz process. For this we do a query to the server and it retrieves in JSON format the status of server

check process domoticz with pidfile /var/run/
start program = "/etc/init.d/ start"
stop  program = "/etc/init.d/ stop"
if failed
       and content = '"status" : "OK"'
   for 2 cycles
   then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"

Here’s what my server Domoticz reference so I’m questioning her from my local network

   "DomoticzUpdateURL" : "",
   "HaveUpdate" : false,
   "Revision" : 4834,
   "SystemName" : "linux",
   "build_time" : "2016-03-02 08:43:51",
   "hash" : "8398125",
   "status" : "OK",
   "title" : "GetVersion",
   "version" : "3.4834"

The Monit script retrieves the value of the key status and check if it is equal to OK . After 2 cycles of failure the service Domoticz is restarted. After 5 rounds in failure, the Raspberry Pi or the computer is restarted.

You can also add this rule (between the then restart and restart if 5) that allows you to restart the Raspberry Pi if the CPU load exceeds 70% for 3 cycles.

Start the Monitoring

We begin by checking the syntax of the configuration file is correct with the command

pi@raspberrypi:~$ sudo monit -t 
Control file syntax OK

If you get Control file syntax OK, there is no error in your configuration file.] Otherwise the line problem is indicated. For example I get sete instead of set on line 19.

 /etc/monit/monitrc:19: syntax error 'sete'

Once everything is OK, we can start Monit

 sudo monit start all

A few seconds after you start you will receive an email that confirms the launch of monitoring

Action done Service domoticz 

    Date:        Mon, 03 Oct 2016 10:28:11
    Action:      alert
    Host:        myhost.mydomain.tld
    Description: start action done

Your faithful employee,

Load a new configuration

After any change in the configuration file, run this command to apply.

 sudo service monit reload

The status of monitoring

Run this command for the status of the monitoring

 sudo monit status

There are many monitoring of the server (CPU, memory, swap…) and the Domoticz process.

Access the web interface

If you have configured permissions for accessing the WEB interface from a computer on your local network, open a Web browser and enter the ip address of the box followed by Automation: 2812. Connect you with the user and password allowed.

The first (Home) page contains a summary of the system.

Click myhost.mydomain.tld to access the details of the server

Click now on Domoticz. We find surveillance rules. Down at the bottom of the page, there is also 4 commands

Suspend monitoring

In some cases, you want to stop monitoring of Domoticz. For example when doing an update including the time will certainly exceed the frequency of monitoring. In this case, we can suspend the monitoring. The easiest way is to use the web interface (seen above). Otherwise, stop monitoring using the following command:

 sudo monit stop all

and to revive

 sudo monit start all

During a stop of the monitoring, the web interface is accessible.

In this tutorial we have seen only a small part of the capabilities of monitoring of Monit. The configuration file contains many other settings pre-configured that suffice to adapt to your needs and configuration: an Apache server monitoring, monitor the permissions on files (why not the health of the database or the Domoticz scripts)… Little regret however, there no graphical representation. Go to the M/Monit version which is paid.

Click to rate this post!
[Total: 1 Average: 5]
Exit mobile version