-
安裝:sudo apt-get install monit
- 配置文件:sudo vim /etc/monit/monitrc
主要配置下面選項:
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