monit设置邮件频率和短信警报
一、monit 配置邮件发送频率
1.1 增加心跳周期
默认为60s 改为120s,可适当在增加
set daemon 120
1.2 增加进程检测周期
将默认的:
check system 192.168.16.204
if loadavg (1min) > 6
if loadavg (5min) > 4
if memory usage > 95%
if swap usage > 95%
if cpu usage (user) > 95%
if cpu usage (system) > 95%
if cpu usage (wait) > 95%
改为如果三次(或更多)都达到警报条件则报警
check system 192.168.16.204
if loadavg (1min) > 6 for 3 cycles then alert
if loadavg (5min) > 4 for 3 cycles then alert
if memory usage > 95% for 3 cycles then alert
if swap usage > 95% for 3 cycles then alert
if cpu usage (user) > 95% for 3 cycles then alert
if cpu usage (system) > 95% for 3 cycles then alert
if cpu usage (wait) > 95% for 3 cycles then alert
二、monit发短信警报
2.1 服务器安装curl
yum install curl
查看rpm -qa|grep curl
2.2 发送短信脚本
#!/bin/bash
/usr/bin/curl -s -d api_id=XXXX -d user=XXXX -d password=**** -d to=86130******** -d "text=$*" "http://api.clickatell.com/http/sendmsg?"
配置例子:
check host localhost with address 192.168.16.204
if failed port 25 type tcp with timeout 10 seconds for 2 times within 3 cycles then exec "/opt/sendsms localhost 192.168.16.204:25 connect failed!"
当senmail 关掉后 会收到短信:localhost 192.168.16.204:25 connect failed!