服务器换机房以后就涉及到需要对服务器做完整的监控,对服务器温度的监控是一个重要的监控,由服务器的温度可以得知服务器的散热情况是否有问题以及机房的空调是否OK。比如服务器风扇坏了会导致服务器的温度升高,那么我们就可以很快地发现并解决。

在网上找到一个工具lm_sensors,很多网友用这个工具来做监控,但是因为我的linux内核版本为2.6.18-194.el5,lm_sensors在该内核版本不支持我的E5504的CPU。总是报Unknown CPU model。只能升级内核版本,对于线上服务器危险系数比较高,因此只有另辟蹊径,咨询DELL的技术人员以后获悉DELL的OMSA(Dell OpenManage Server Administrator)能获得机箱的温度,OMSA是DELL提供的一组集成管理服务,可以对本地和远程的服务器进行管理和监控。
接下来就来描述如何通过OMSA获取服务器的温度,并通过cacti和nagios来进行监控。
1.   安装和使用OMSA 6.5 (centos5.5_64bit)
A. 安装OMSA 6.5
wget -q -O - http://linux.dell.com/repo/hardware/latest/bootstrap.cgi | bash
yum install -y srvadmin-base
yum install -y srvadmin-storageservices
B.   禁用OMSA自带的snmp功能
/opt/dell/srvadmin/sbin/dcecfg command=disablesnmp
C.   启动OMSA
/opt/dell/srvadmin/sbin/srvadmin-services.sh start
D.   获取温度的命令
/opt/dell/srvadmin/sbin/omreport chassis temps
2.   使用cacti监控系统温度
下面是使用cacti来调用OMSA监控系统温度的脚本
cat /etc/snmp/monitor_tem_cacti.sh
 
  1. #!/bin/bash
  2. #Purpose: Monitor the classis's temperature -----cacti
  3. #Author: 飞鸿无痕
  4. #Date: 2012-09-07
  5. #define the path for the executable file
  6. TEMPPATH='/opt/dell/srvadmin/sbin'
  7. #use del omreport tool to get the classis's temperature
  8. TEMP=`$TEMPPATH/omreport chassis temps | grep "Reading" | awk '{print $3}'`
  9. echo $TEMP
脚本内容保存以后还需要更改/etc/snmp/snmpd.conf配置文件,添加如下一行:
extend .1.3.6.1.4.1.2021.25 monitor_temperature /bin/bash /etc/snmp/monitor_tem_cacti.sh
然后重启snmp服务
/etc/rc.d/init.d/snmpd restart
然后直接在cacti端添加数据模板、图形模板然后添加到主机中就可以了,附件附上自己监控的cacti图形模板。
3.   使用Nagios监控系统温度
下面是使用nagios调用OMSA监控系统温度的脚本
cat /usr/local/nagios/libexec/monitor_tem_nagios.sh
 
  1. #!/bin/bash
  2. #Purpose: Monitor the classis's temperature -----nagios
  3. #Author: 飞鸿无痕
  4. #Date: 2012-09-07
  5. #Status OK: the temperature greater than or equal 8 and less than or equal 42

  6.  
  7. #define the exist status
  8. STATE_OK=0
  9. STATE_WARNING=1
  10. STATE_CRITICAL=2
  11. STATE_UNKNOWN=3
  12. #define the path for the executable file
  13. TEMPPATH='/opt/dell/srvadmin/sbin'
  14. #use del omreport tool to get the classis's temperature
  15. TEMP=`$TEMPPATH/omreport chassis temps | grep "Reading" |awk -F'[ .]+' '{print $3}'`
  16. if [ $? -ne 0 ];then
  17. echo "Please Check the temperature Plugins"
  18. exit $STATE_UNKNOWN
  19. fi
  20. if [ "$TEMP" -ge 8 -a "$TEMP" -le 42 ];then
  21. echo "Check OK,The classis's temperature is: $TEMP"
  22. exit $STATE_OK
  23. elif [ "$TEMP" -ge 3 -a "$TEMP" -lt 8 -o "$TEMP" -gt 42 -a "$TEMP" -lt 47 ];then
  24. echo "Check WARNING,The classis's temperature is: $TEMP"
  25. exit $STATE_WARNING
  26. else
  27. echo "Check Critical,The classis's temperature is: $TEMP"
  28. exit $STATE_CRITICAL
  29. fi
这个脚本会在系统的温度小于8度或者高于47度的时候自动通过nagios报警。设置完这个脚本还需要更改/usr/local/nagios/etc/nrpe.cfg配置文件,添加如下内容:
command[check_temperature]=/usr/local/nagios/libexec/monitor_tem_nagios.sh
然后在nagios服务器端添加check_temperature的监控即可。
4.   自动配置cacti和nagios使用OMSA监控系统温度脚本
将上面的cacti和nagio监控的脚本保存到和下面的脚本在一个目录下,不要更改脚本的名字。使用下面的脚本安装完成OMSA后会自动配置cacti和nagios。
 
cat monitor_tem_install.sh
 
  1. #!/bin/bash
  2. #Purpose: install Dell OpenManage Server Administrator tool(OMSA) and configure cacti and nagios client
  3. #Author: 飞鸿无痕
  4. #Date: 2012-09-07

  5.  
  6. #download the file and install
  7. wget -q -O - http://linux.dell.com/repo/hardware/latest/bootstrap.cgi | bash
  8. yum install -y srvadmin-base srvadmin-storageservices
  9. #disable the omsa's snmp
  10. /opt/dell/srvadmin/sbin/dcecfg command=disablesnmp
  11. #start amsa
  12. /opt/dell/srvadmin/sbin/srvadmin-services.sh start
  13. #add monitor script to snmp directory
  14. cp monitor_tem_cacti.sh /etc/snmp/
  15. chmod +x /etc/snmp/monitor_tem_cacti.sh
  16. echo "extend .1.3.6.1.4.1.2021.25 monitor_temperature /bin/bash /etc/snmp/monitor_tem_cacti.sh" >> /etc/snmp/snmpd.conf
  17. /etc/rc.d/init.d/snmpd restart
  18. #add monitor script to nagios directory
  19. cp monitor_tem_nagios.sh /usr/local/nagios/libexec/
  20. echo "command[check_temperature]=/usr/local/nagios/libexec/monitor_tem_nagios.sh" >> /usr/local/nagios/etc/nrpe.cfg
  21. kill -9 $(ps -ef | grep nrpe | grep -v grep | awk '{print $2}')
  22. /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

监控系统温度的cacti模板:
http://down.51cto.com/data/756245

安装和部署OMSA监控温度的脚本:
http://down.51cto.com/data/756252