Is it possible to use monit
to count the number of instances of a process (in my case Celery
) and take an action accordingly.
For example if there are 4 instances of celery daemon, then take action
This should be doable using a short shell script, and program status testing. Something like
check program countCelery with path /usr/local/bin/countCelery.sh with timeout 600 seconds:
if status != 0 alert
with a shell script like:
#!/bin/bash
celery_count=$(pgrep -c Celery)
if [[ $celery_count -gt 4 ]]; then
exit 1
else:
exit 0
fi