1

I have a service monitored by monit, and I would like to restart it if it meets either one of two distinct conditions:

  1. if memory usage is >15%
  2. if memory usage is >5% AND the current system time is between 4AM and 6AM.

Here is an example of a monit configuration that will handle the former case:

check process myservice with pidfile /var/run/myscript.pid
    start = "/bin/systemctl start myservice.service"
    stop = "/bin/systemctl stop myservice.service"
    if mem usage > 10% for 3 cycles then restart

And a config file that will handle the latter case (I think -- haven't actually tested this):

check process myservice with pidfile /var/run/myscript.pid
    every "* 4-6 * * *"
    start = "/bin/systemctl start myservice.service"
    stop = "/bin/systemctl stop myservice.service"
    if mem usage > 5% for 3 cycles then restart

But how can I combine these two conditions?

(Background on the use case: the service is expected to slowly increase in RAM under normal usage, say 1% per day, but a restart would be somewhat disruptive during the period during which the service is actually being used, i.e. the daytime. Thus the second case handles expected intermittent nightly restarts of the service. The first case is for unexpected pathological scenarios, where the RAM usage is quickly increasing.)

abeboparebop
  • 111
  • 3

0 Answers0