Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
cool. i will test this right away and let u know –  aqs May 22 '13 at 13:25
    
This worked, thanks a lot –  aqs May 23 '13 at 10:18
    
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 at 20:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.