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.