check program OpenSocket with path "/bin/checkn_socket.sh"
if status > 0 then alert
group admin
脚本:checkn_socket.sh
#!/bin/bash
Threshold=4 # Set Threshold
TotalEstSocket=$(netstat -t | awk '{/ESTABLISHED/ && n++} END{ print n }')
if (( TotalEstSocket >= Threshold ))
then
echo >&2 "Too Many OpenSocket"
exit $TotalEstSocket
else
exit 0
fi
监控日志
[IST Sep 12 22:32:14] error : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:17] info : 'OpenSocket' status succeeded
[IST Sep 12 22:32:26] error : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:29] error : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:32] error : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:35] info : 'OpenSocket' status succeeded
这是另一个解决方案
定义以下配置监视器:
脚本:checkn_socket.sh
监控日志
它似乎没有直接支持,但我想出了一个 hack。
确定每分钟 ESTABLISHED 连接的数量,并写入具有相同数量的零字节的文件。
然后,设置 Monit 来检查这个 zeros 文件的文件大小。如果它得到“太大”的警报。
在某些用户的 crontab 中:
在监视器配置中: