如何用户monit来统计进程的实例数目

是否有可能使用monit来统计进程的实例数量(在我的情况下, Celery ),并采取相应的行动。

例如,如果有4个芹菜守护进程的实例,那么采取行动

这应该是可行的,使用一个简短的shell脚本和程序状态testing。 就像是

 check program countCelery with path /usr/local/bin/countCelery.sh with timeout 600 seconds: if status != 0 alert 

与一个shell脚本如:

 #!/bin/bash celery_count=$(pgrep -c Celery) if [[ $celery_count -gt 4 ]]; then exit 1 else: exit 0 fi