[root@server146 monitoring]# ls -l /var/www/html/monitoring 总计 28 -rw-r--r-- 1 munin munin 2555 07-22 15:15 definitions.html -rw-r--r-- 1 munin munin 1584 07-23 17:00 index.html drwxr-xr-x 2 munin munin 12288 07-22 15:15 localhost -rw-r--r-- 1 munin munin 473 07-22 15:15 logo.png -rw-r--r-- 1 munin munin 3538 07-22 15:15 style.css |
通过 http://ip/monitoring/ 就可以查看到主机的监控信息 http:#192.168.1.146/monitoring/localhost/localhost.html#Network 图: Munin 监控信息
图: Munin 监控信息每天
图: Munin 监控信息每周
安装和配置 monit
执行 yum 完成安装
yum install monit |
chkconfig --levels 235 monit on
默认的 /etc/monit.conf 文件中是注释的示例配置文件, http:#mmonit.com/wiki/Monit/ConfigurationExamples 这里是官方提供的配置文件参考。
http:#mmonit.com/monit/documentation/monit.html 这里是详尽的配置文件的语法格式信息。
大家注意到 /etc/monit.conf 文件末尾的信息。
############################################################################### ## Includes ############################################################################### ## ## It is possible to include additional configuration parts from other files or ## directories. # include /etc/monit.d/* # # |
此处的信息的作用是与apache的配置文件类似,在/etc/monit.d/中的每个文件都是一个独立的配置文件,便于配置文件的结构化和维护操作。
创建一个简单的配置文件
vi /etc/monit.d/monitrc set daemon 60 #每2分钟检查一次 set logfile syslog facility log_daemon #monit的日志文件 set mailserver localhost #设置邮件服务器 set mail-format { from: monit@192.168.1.149 } #出现错误的时候发报警邮件到指定的邮箱 set alert lvsheat@qq.com set httpd port 2812 and use address 192.168.1.149 #设置http监控页面的端口和ip SSL ENABLE PEMFILE /var/certs/monit.pem allow admin:test #认证的用户名和密码 #平均负载.内存使用率,cpu使用率 check system 192.168.1.149 if loadavg (1min) > 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert # 磁盘空间使用率 check device data with path /dev/sda2 if space usage > 90% then alert if inode usage > 85% then alert check device home with path /dev/sda3 if space usage > 85% then alert if inode usage > 85% then alert #监控vsftpd服务 check process vsftpd with pidfile /var/run/vsftpd.pid start program = "/etc/init.d/vsftpd start" stop program = "/etc/init.d/vsftpd stop" if failed port 21 protocol ftp then restart if 5 restarts within 5 cycles then timeout #监控ssh服务 check process sshd with pidfile /var/run/sshd.pid start program "/etc/init.d/sshd start" stop program "/etc/init.d/sshd stop" if failed port 22 protocol ssh then restart if 5 restarts within 5 cycles then timeout #监控mysql服务 check process mysql with pidfile /var/run/mysqld/mysqld.pid group database start program = "/etc/init.d/mysqld start" stop program = "/etc/init.d/mysqld stop" if failed host 127.0.0.1 port 3306 then restart if 5 restarts within 5 cycles then timeout #监控apache服务 check process apache with pidfile /var/run/httpd.pid group www start program = "/etc/init.d/httpd start" stop program = "/etc/init.d/httpd stop" if failed host 192.168.1.149 port 80 protocol http and request "/monit/testok" then restart if cpu is greater than 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart if totalmem > 500 MB for 5 cycles then restart if children > 250 then restart if loadavg(5min) greater than 10 for 8 cycles then stop if 3 restarts within 5 cycles then timeout #监控postfix 邮件服务 check process postfix with pidfile /var/spool/postfix/pid/master.pid group mail start program = "/etc/init.d/postfix start" stop program = "/etc/init.d/postfix stop" if failed port 25 protocol smtp then restart if 5 restarts within 5 cycles then timeout #监控自定义服务 check process web_lb with pidfile /opt/server/web_lb/httpd.pid start program = "/opt/bin/lb.sh" #启动脚本 stop program = "/opt/bin/lb_stop.sh" #停止脚本 if failed host 192.168.1.149 port 6101 proto http then restart if failed host 192.168.1.149 port 6101 proto http for 5 times within 5 cycles then exec "/opt/bin/lb_pay.sh" if failed host 192.168.1.149 port 6102 type TCPSSL proto http then restart if failed host 192.168.1.149 port 6102 type TCPSSL proto http for 5 times within 5 cycles then exec "/opt/bin/lb_pay.sh |