我有一个进程需要运行多个实例。我想用 Monit 来监控它。
目前这就是我所做的。
check program maintain_workers with path maintain_workers.sh user "command p1" 5
every "* * * * *"
if status != 0 then alert
调用此脚本:
# Maintain the number of programs at certain limit
USER=$1
COMMAND=$2
LIMIT_WORKERS=$3
NUM_WORKERS=`pgrep -u "$USER" -f "$COMMAND" | wc -l`
if [ $NUM_WORKERS -lt $LIMIT_WORKERS ]
then
STARTNUM=$(( $LIMIT_WORKERS - $NUM_WORKERS ))
echo "Only $NUM_WORKERS workers detected. Starting $STARTNUM workers"
for (( i=0; i < STARTNUM ; i++ ))
do
$COMMAND &
echo "Ran worker $(( i + 1 ))"
done
fi
# Do a final check
NUM_WORKERS=`pgrep -u "$USER" -f "$COMMAND" | wc -l`
exit $(( $LIMIT_WORKERS - $NUM_WORKERS ))
但是它不允许我监控每个实例的 CPU 或内存使用情况。
另一种方法是只使用n
以下方法:
check process command0 with pidfile command0.pid
start = "command.sh start 0"
stop = "command.sh stop 0"
但这显然更难扩展,我想应该有更好的方法。有人能帮我吗?谢谢!