Hello David,
nice idea, have a look to
https://mmonit.com/monit/documentation/monit.html#UPTIME-TEST
https://mmonit.com/monit/documentation/monit.html#EXIST

Try to combine "exits" and "uptime" to stop a running process.

check process sleep matching "sleep"
  start program "/bin/ksh -c '/bin/echo start; /bin/sleep 300 &'"
  stop program "/bin/ksh -c 'kill -9 `ps -fu $USER | awk "/[Ss]leep/ {
print \\\\$2 }"`'"
  if uptime > 3 minutes then alert
  if uptime > 5 minutes then exec "/bin/ksh -c 'kill -9 `ps -fu $USER |
awk "/[Ss]leep/ { print \\\\$2 }"`'"
  if exist for 10 cycles then exec "/bin/ksh -c 'kill -9 `ps -fu $USER |
awk "/[Ss]leep/ { print \\\\$2 }"`'"

As long as the process is available the status is "Exists" and if the
process is not available the status is "OK".

Unfortunately you can not use "stop" to stop the process because this
will set the monitor status to "unmonitor", this will stop monitoring
the process in general.

Monit check all processes called "sleep" and send an alert after 3
minutes and stop the process after 5 minutes. The exists test stop the
process also.

A sample only,
Lutz

Reply via email to