3

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

aqs
  • 163
  • 1
  • 6

1 Answers1

6

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
Cian
  • 5,777
  • 1
  • 27
  • 40
  • cool. i will test this right away and let u know – aqs May 22 '13 at 13:25
  • In the version of Monit we use, the syntax is -- check program countCelery with path /usr/local/bin/countCelery.sh with timeout 30 seconds if status != 0 then alert – tgharold Jun 16 '14 at 20:32