############################################################### #Global section #全局配置 ############################################################### set daemon 120 with start delay 240 #设置monit为后台进程,没2分钟为一个检查周期,首次启动后4分钟开始第一次检查 ############################################################### set logfile syslog facility log_daemon #设置系统日志,这是默认设定,可以手动配置指定日志文件 ############################################################### set idfile /var/.monit.id #设置monit对象实例,其实这里的对象就是指本机 ############################################################### set statefile /var/.monit.state #设置状态报告文件 ############################################################### set mailserver mail.tiigame.com #设置邮件服务器,通过它来发送邮件警告 ############################################################### set eventqueue basedir /var/monit #设置事件报告,每个事件对应的文件最大大小为100KB slots 100 ############################################################### ##Monit by default uses the following alert mail format: ##--8 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert #检查负载 if swap usage > 25% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert ############################################################### check file apache_bin with path /usr/local/apache/bin/httpd if failed checksum and expect the sum 8f7f419955cefa0b33a2ba316cba3659 then unmonitor if failed permission 755 then unmonitor if failed uid root then unmonitor #apache权限检查 if failed gid root then unmonitor alert 244032545@qq.com on {checksum, permission, uid, gid} with the mail-format { subject: Alarm! } group server ############################################################### check process apache with pidfile /usr/local/apache/logs/httpd.pid start program = "/etc/init.d/httpd start" with timeout 60 seconds stop program = "/etc/init.d/httpd stop" if cpu > 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart if totalmem > 200.0 MB for 5 cycles then restart#检查apache服务器负载 if children > 250 then restart if loadavg(5min) greater than 10 for 8 cycles then stop if failed host www.tildeslash.com port 80 protocol http and request "/somefile.html" then restart if failed port 443 type tcpssl protocol http with timeout 15 seconds then restart if 3 restarts within 5 cycles then timeout depends on apache_bin group server ############################################################### check filesystem datafs with path /dev/sdb1 start program = "/bin/mount /data" stop program = "/bin/umount /data" if failed permission 660 then unmonitor if failed uid root then unmonitor #检查磁盘使用情况 if failed gid disk then unmonitor if space usage > 80% for 5 times within 15 cycles then alert if space usage > 99% then stop if inode usage > 30000 then alert if inode usage > 99% then stop group server ############################################################### check file database with path /data/mydatabase.db if failed permission 700 then alert if failed uid 0 then alert if failed gid 0 then alert #数据库 if timestamp > 15 minutes then alert #if size > 100 MB then exec "/my/cleanup/script" as uid dba and gid dba ############################################################### check directory bin with path /bin if failed permission 755 then unmonitor #检查某个目录,这里是/bin if failed uid 0 then unmonitor if failed gid 0 then unmonitor ############################################################### ##以下设置对一台远程主机的监控 ############################################################### #Check a remote host availability by issuing a ping test and check the # content of a response from a web server. Up to three pings are sent and #connection to a port and an application level network check is performed. # check host myserver with address 192.168.1.1 # if failed icmp type echo count 3 with timeout 3 seconds then alert # if failed port 3306 protocol mysql with timeout 15 seconds then alert # if failed url http://user:password@www.foo.bar:8080/?querystring # and content == 'action="j_security_check"' then alert ############################################################### ##配置包含文件,这样管理起来可能更方便些,不至于主配置文件代码太多 ############################################################### #Includes #It is possible to include additional configuration parts from other #files or directories. #include /etc/monit.d/* ###############################################################