monit
Posted: 25 Nov 2022 06:08
For those that would like to use monit to monitor z-way or other processes, the install of monit is quite simple.
Install 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.
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:
I added a # in front of the default and added a line for 15 seconds so my portion of that config looks like this:
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:
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:
In that file I have the following configuration:
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.
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:
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.
Install monit:
Code: Select all
sudo apt install -y monit
Code: Select all
sudo vi /etc/monit/monitrc
The default line is this:
Code: Select all
set daemon 120 # check services at 2-minute intervals
Code: Select all
set daemon 15 # check services at 15 second intervals
# set daemon 120 # check services at 2-minute intervals
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'
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
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
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/
Lastly you need to restart monit for it to pickup the changes:
Code: Select all
sudo service monit restart
I would be interested in seeing how other have monit configured on their systems.