每次testing失败时,如何停止运行exec语句的monit? 我的monitrc中的声明是:
check filesystem tmpfs with path /var if space > 90% then exec "/usr/bin/logger -p daemon.crit 'MAJOR: space test'"
这似乎很奇怪,因为有人问了一个问题,他正在做一个警戒,它有我想要的行为。 我已经准备好开始窒息linux框。
编辑:这里是相反的情况重复监控警报
是因为他使用alert而不是exec吗?
我不得不几次处理类似的问题。
事实是, monit不能做到这一点,据我所知。
通过monit您可以处理X times和/或Y cycles指令,但exec动作或多或less会快速触发不止一次,具体取决于您花费的时间来解决问题。
所以,最后,我决定写我自己的检查脚本来处理所有的逻辑,基于标志。
我会和你分享一下,然后你是否接受,这取决于你。
首先:编写脚本来监视FS使用情况,比如/root/check_fsspace.sh :
#!/bin/sh myFS=/var myTreshold=90 flagFile=/tmp/flag spaceused=$(df -h | grep "$myFS" | tr -s " " | cut -d" " -f5 | cut -d"%" -f1) if [ $spaceused -gt $myTreshold ]; then if [ ! -f $flagFile ]; then touch $flagFile exit 1 else exit 0 fi fi if [ $spaceused -le $myTreshold ]; then rm -f $flagFile exit 0 fi
在这里,我假设你可以理解脚本。 如果没有,告诉我,我会解释它。
其次:设置您的monit服务定义:
check program check_fs with path "/root/check_fsspace.sh" if status != 0 then exec "/usr/bin/logger -p daemon.crit 'MAJOR: space test'"
你可以用cycles指令来控制它。 您多长时间才能logging一次?
假设Monit守护进程检查间隔为60秒,则可以这样说:“如果这在X个周期内失败,则执行脚本”。
但是Monit很简单…每当你达到这个磁盘的门槛时,它都会报警。 这是devise。 如果您足够频繁地触发阈值,这种日志logging操作会很烦人,请尝试更改阈值。
Monit会将每个周期的状态logging到消息日志中。
Mar 12 00:07:06 yo-mama monit[8577]: 'ppro' space usage 92.4% matches resource limit [space usage>85.0%] Mar 12 00:08:06 yo-mama monit[8577]: 'ppro' space usage 92.4% matches resource limit [space usage>85.0%] Mar 12 00:09:06 yo-mama monit[8577]: 'ppro' space usage 92.4% matches resource limit [space usage>85.0%] Mar 12 00:09:07 yo-mama monit[8577]: 'ppro' space usage 92.4% matches resource limit [space usage>85.0%]
每次超过阈值时都会提示:
Resource limit matched Service ppro Date: Wed, 12 Mar 2014 00:09:07 Action: alert Host: yo-mama Description: space usage 92.4% matches resource limit [space usage>85.0%] Your faithful employee, Monit