monit

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Post Reply
lanbrown
Posts: 279
Joined: 01 Jun 2021 08:06

monit

Post by lanbrown »

For those that would like to use monit to monitor z-way or other processes, the install of monit is quite simple.

Install monit:

Code: Select all

sudo apt install -y monit
Now that the easy part is taken care of, now you need to use sudo and your favorite editor to make changes. I prefer vi some prefer nano.

Code: Select all

sudo vi /etc/monit/monitrc
I modified it to monitor at 15 second intervals instead of the default of 120 seconds. This is up to you if you want to change it.
The default line is this:

Code: Select all

  set daemon 120            # check services at 2-minute intervals
I added a # in front of the default and added a line for 15 seconds so my portion of that config looks like this:

Code: Select all

  set daemon 15            # check services at 15 second intervals
#  set daemon 120            # check services at 2-minute intervals
If you want to be able to use a web browser so you can see the status of the monitored processes then you need to modify this section in the same config file as above:

Code: Select all

 set httpd port 2812 and
#     use address localhost  # only accept connection from localhost (drop if you use M/Monit)
     allow localhost        # allow localhost to connect to the server and
     allow YourLocalNetwork/CIDR
     allow admin:monit      # require user 'admin' with password 'monit'
If you local network is 192.168.1.0 255.255.255.0 then you would use:
allow 192.168.1.0/24
If you only want to be able to access it from the Raspberry Pi itself, then that is covered by the allow localhost

You can add what you want to be monitored to this same file, you will see examples in it. I prefer the cleaner approach and that is to put it in a file in
/etc/monit/conf-available

Once again use your favorite editor:

Code: Select all

sudo vi /etc/monit/conf-available/z-way-server
In that file I have the following configuration:

Code: Select all

check process z-way-server with pidfile /var/run/z-way-server.pid
	start program "/etc/init.d/z-way-server start"
	stop program "/etc/init.d/z-way-server stop"
	if failed port 8083 protocol http then restart
	if 5 restarts with 5 cycles then timeout
        if cpu > 80% for 5 cycles then restart
        if totalmem > 800.0 MB for 5 cycles then restart
        if children > 250 then restart
        if loadavg(5min) greater than 3 for 8 cycles then stop
Some of that config is self explanatory.

The first line is telling it of the process and where the pid file is.

The start and stop commands are telling it how to start and stop the process.

The fourth line is checking reachability on port 8083 using http and if a connection cannot be established it is viewed as failed and to restart the process.

The fifth line is if it restarts and then has to keep restarting as it keeps failing, then timeout. Z-Way won't be restarted a sixth time. This means there is obviously an issue that require intervention on your part.

The sixth line is if the CPU usage is > 80 for five cycles (my cycle is 15 seconds) then restart the process. You can set the CPU usage to whatever you like or feel is appropriate for your setup.

The seventh line is for memory. 800.0 MB is a lot of memory and Z-Way doesn't use anywhere close to that which is why I also used that value, it would be well outside the norm and clearly an indication of something gone awry. If you have a Pi with 512MB of RAM, that would not be a valid configuration setting since it could never be reached. My Pi's have 8GB of RAM, so that amount of memory use could be achieved. So this setting should fit what your system has and where your z-way process currently uses for memory usage.

The eighth line would be where a bunch of children processes have been spawned. This probably is not used but in case Z-Way does start to spawn child processes if it gets out of hand, it will eventually get restarted.

That monit configuration file is in the conf-available and not the conf-enabled. This is done for a reason. Use this command link the file from available to enabled.

Code: Select all

sudo ln -s /etc/monit/conf-available/z-way-server /etc/monit/conf-enabled/
If you ever want to get rid of that being a monitored process, you just delete it (rm) from the conf-enabled but it will stay in conf-available as all the rm command did was remove the link, not the actual file.

Lastly you need to restart monit for it to pickup the changes:

Code: Select all

sudo service monit restart
You can access the monit monitoring page by using a browser and just using port 2812 instead of 8083. If this is reachable off the Raspberry Pi itself depends on what you have configured for port 2812 near the top of this post. In my case I can access from my computer to the Raspberry Pi running Z-Way.

I would be interested in seeing how other have monit configured on their systems.
harre
Posts: 95
Joined: 24 Nov 2020 02:22

Re: monit

Post by harre »

I didn't know about monit before and it looks nice.
piet66
Posts: 266
Joined: 04 Feb 2017 17:00

Monitorix

Post by piet66 »

I see the advantage of monit in the automatic restart after failure abort.

Those who don't need that and prefer a graphical interface can have a look on Monitorix (http://www.monitorix.org/).
Already in standard view, it provides a lot of information.

In /etc/monitorix/monitorix.conf, section <process> you can add user processes for monitoring.
Example for ZWay:

Code: Select all

<process>
	<list>
		#0 = httpd, sshd, ntpd, mysqld, proftpd, clamd, imap, sendmail, named, smbd
		1 = z-way-server
	</list>
	<desc>
		httpd = Apache
		imap = Dovecot
		named = Bind
	</desc>
	rigid = 2, 0, 0, 0, 0, 0, 0, 0
	limit = 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000
</process>
For displaying the graph, you have to enable 'process' in <graph_enable> section.
Screenshot 2022-11-26 at 14-55-46 raspberrypi Monitoring.png
Screenshot 2022-11-26 at 14-55-46 raspberrypi Monitoring.png (153.07 KiB) Viewed 9810 times
Enabling 'raspberrypi' displays Raspberry Pi specific sensor values.
Screenshot 2022-11-26 at 14-58-04 raspberrypi Monitoring.png
Screenshot 2022-11-26 at 14-58-04 raspberrypi Monitoring.png (57.34 KiB) Viewed 9810 times
It's contained in the Raspbian repository (not the latest version). You can install it with 'sudo apt install monitorix'.
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v3.2.3 from 2022-04-06 04:56:23 +0300
Post Reply