主要配置下面选项:
SMTP服务器用于外发邮件,这里使用的是AWS Simple Mail Service
set mailserver email-smtp.us-west-xx.amazonaws.com port 587
username "AKIAJxxxxxxxxxxxxxxxx" password "Axxxxxxxxxxxxxxxxxxxxxxxxxxx"
using tlsv1
with timeout 30 seconds
收集人
#email address which will receive monit alerts
set alert [email protected]
如果不需要monit每次reload都给自己发邮件
set alert [email protected] not {instance}
邮件格式
set mail-format {
from: [email protected]
subject: XXX alert -- $EVENT $SERVICE
message: $EVENT Service $SERVICE
Date: $DATE
Action: $ACTION
Host: XXX Server
Description: $DESCRIPTION
Monitor System
}
启用http
Enable httpd: set httpd port 2812
#Then: sudo monit reload
#Then: localhost:2812
这份配置文件已经包含很多监控选项,可以根据需求设定
- 启动monit:sudo monit
- 其它常用命令
sudo monit status
sudo service monit status
sudo monit reload = sudo service monit restart
Check log:
sudo tail -f /var/log/monit.log
grep sshd /var/log/monit.log
Check syntax:
sudo monit -t
- 如果需要定制自己的监控项目,可以把配置文件保存在这里:/etc/monit/conf.d/
- 监控磁盘剩余空间报警
sudo vim /etc/monit/conf.d/storagespace
- 监控磁盘剩余空间报警
check filesystem Media with path /dev/sdb1df
if space usage > 90% then alert
- 监控挂载的外部文件夹
check filesystem Compal-NAS-Croissant with path /test/ABC
if changed fsflags then alert
-监控网络连接
check host WWW with address 192.20.1.40
if failed ping then alert
原文地址:https://blog.51cto.com/helpdesk/2467293
时间: 2024-10-28 05:24:06