现在国内的主流开源监控以nagios为首,nagios确实功能足够的强,已经成了监控行业的工业标准。而且能和其他一些出色的监控工具(如:cacti 、Ganglia)进行整合。对于一般的公司使用来说,已经足够了。不过了解一下其他监控软件也未尝不可,可以在一些方面对nagios做个补充和对比。
无意间在网上看到了开源监控工具monit,网上对其的评价颇高。很多人称其为神器。所以我也试了下其具体效果。使用心得也记录下。
一、monit的安装
其下载页面为http://mmonit.com/monit/download/ ,根据自己的系统版本不同,可以选择相应的发行版(目前最近版为5.5版)。此处我选择的是linux-x86版 。
wget http://mmonit.com/monit/dist/binary/5.5/monit-5.5-linux-x64.tar.gz tar zxvf monit-5.5-linux-x64.tar.gz cp monit-5.5/bin/monit /usr/local/bin/monit cp monit-5.5/conf/monitrc /etc/
因为该软件是直接编绎好的,直接拿来就可以使用。我方面我倒是很喜欢。其配置起来倒是比nagios简单。只有一个配置文件monitrc 。
二、配置
set daemon 60 # check services at 1-minute intervals set logfile syslog facility log_daemon set idfile /var/.monit.id set statefile /var/.monit.state set mailserver localhost set eventqueue basedir /var/monit # set the base directory where events will be stored slots 1000 # optionally limit the queue size set mmonit http://monit:monit@192.168.10.24:8080/collector # 配置mmonit的连接信息上面的monit:monit是mmonit上面的用户名和密码 set mail-format { from: monit@$HOST subject: monit alert -- $EVENT $SERVICE message: $EVENT Service $SERVICE Date: $DATE Action: $ACTION Host: $HOST Description: $DESCRIPTION Your faithful employee, Monit } set alert test@361way.com reminder only on 3 cycles #设置超出伐值几次收到邮件告警 set httpd port 2812 and use address 192.168.10.24 #此处地址要改成自己的IP,用默认localhost时,其他主机通过http无法访问 allow localhost # allow localhost to connect to the server and allow 192.168.10.24 # allow localhost to connect to the server and allow 192.168.20.168 # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit' allow @monit # allow users of group 'monit' to connect (rw) allow @users readonly # allow users of group 'users' to connect readonly check system host24 if loadavg (1min) > 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 filesystem gen with path / if space usage > 70% then alert if inode usage > 85% then alert check filesystem boot with path /boot if space usage > 70% then alert if inode usage > 85% then alert check process nginx with pidfile /usr/local/nginx/logs/nginx.pid start program = "/usr/local/nginx/sbin/nginx" stop program = "/usr/local/nginx/sbin/nginx -s stop" if failed host 192.168.10.24 port 80 protocol http then restart if cpu > 60% for 2 cycles then alert if cpu > 80% for 5 cycles then restart include /etc/monit.d/* #可以将其他配置放到这个目录里
上面是一个简单的配置示例,具体每一项的含义在monitrc文件里都有说明。如果想对其他服务进行监控,可以参看官方上的示例。
三、运行和查看
可以通过monit -c /etc/monitrc 进行启动。后面的-c选项也可以不加,不加的话其默认会从~/monitrc 、/etc/monitrc两个位置去找配置文件。其他相关参数可通过monit -h查看。启动完成后,可以通过http://IP:2812(端口可以在配置文件中进行更改) 查看具体监控信息(默认用户名密码是admin monit)。下图为登录后的监控截图
详细帮忙文件可以通过 less monit-5.5/man/man1/monit.1 查看man手册。也可以查看官方wiki页面上的帮助文档。
四、总结
该工具为C语言写成,处理效率上非常高。占用资源非常低(几乎不占用资源),配置参数十分简单——只是几个if 、then语句就可以完成。尤其适用于对某些进程进行守护。如在检测到http服务不正常时,自动重启apache或nginx 。但监控功能,相较nagios略显简单。