脚本监控服务器CPU温度

一,系统环境

   Centos6.2 x86_64

   IP:192.168.0.21

   1,首先安装sensors命令

yum install -y lm_sensors

   2,执行sersors

[root@test ~]# sensors
No sensors found!
Make sure you loaded all the kernel drivers you need.
Try sensors-detect to find out which these are.

   3,报错的话提示你执行sensors-detect

[root@test ~]# sensors-detect
# sensors-detect revision 1.1
# System: VMware, Inc. VMware Virtual Platform
# Board: Intel Corporation 440BX Desktop Reference Platform
This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing.
Some south bridges, CPUs or memory controllers contain embedded sensors.
Do you want to scan for them? This is totally safe. (YES/no): yes
Silicon Integrated Systems SIS5595...                       No
VIA VT82C686 Integrated Sensors...                          No
VIA VT8231 Integrated Sensors...                            No
AMD K8 thermal sensors...                                   No
AMD Family 11h thermal sensors...                           No
Intel digital thermal sensor...                             Success!
    (driver `coretemp')
Intel AMB FB-DIMM thermal sensor...                         No
VIA C7 thermal and voltage sensors...                       No
Some Super I/O chips contain embedded sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no): yes
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor'...                   Yes
Found unknown chip with ID 0x0f00
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor'...                   No
Trying family `SMSC'...                                     No
Trying family `VIA/Winbond/Nuvoton/Fintek'...               No
Trying family `ITE'...                                      No
Some systems (mainly servers) implement IPMI, a set of common interfaces
through which system health data may be retrieved, amongst other things.
We first try to get the information from SMBIOS. If we don't find it
there, we have to read from arbitrary I/O ports to probe for such
interfaces. This is normally safe. Do you want to scan for IPMI
interfaces? (YES/no): yes
Probing for `IPMI BMC KCS' at 0xca0...                      No
Probing for `IPMI BMC SMIC' at 0xca8...                     No
Some hardware monitoring chips are accessible through the ISA I/O ports.
We have to write to arbitrary I/O ports to probe them. This is usually
safe though. Yes, you do have ISA I/O ports even if you do not have any
ISA slots! Do you want to scan the ISA I/O ports? (YES/no): yes
Probing for `National Semiconductor LM78' at 0x290...       No
Probing for `National Semiconductor LM79' at 0x290...       No
Probing for `Winbond W83781D' at 0x290...                   No
Probing for `Winbond W83782D' at 0x290...                   No
Lastly, we can probe the I2C/SMBus adapters for connected hardware
monitoring devices. This is the most risky part, and while it works
reasonably well on most systems, it has been reported to cause trouble
on some systems.
Do you want to probe the I2C/SMBus adapters now? (YES/no): yes
Using driver `i2c-piix4' for device 0000:00:07.3: Intel 82371AB PIIX4 ACPI
Module i2c-dev loaded successfully.
Now follows a summary of the probes I have just done.
Just press ENTER to continue:
Driver `coretemp':
  * Chip `Intel digital thermal sensor' (confidence: 9)
Do you want to overwrite /etc/sysconfig/lm_sensors? (YES/no): yes
Starting lm_sensors: loading module coretemp [确定]
Unloading i2c-dev... OK

   4,然后重启服务器。重启后可以运行命令

[root@mail5 ~]# sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +35.0°C  (high = +87.0°C, crit = +97.0°C) 
Core 1:      +31.0°C  (high = +87.0°C, crit = +97.0°C) 
Core 2:      +37.0°C  (high = +87.0°C, crit = +97.0°C) 
Core 3:      +31.0°C  (high = +87.0°C, crit = +97.0°C) 
coretemp-isa-0004
Adapter: ISA adapter
Core 0:      +37.0°C  (high = +87.0°C, crit = +97.0°C) 
Core 1:      +39.0°C  (high = +87.0°C, crit = +97.0°C) 
Core 2:      +41.0°C  (high = +87.0°C, crit = +97.0°C) 
Core 3:      +39.0°C  (high = +87.0°C, crit = +97.0°C)

   5,写脚本取值,温度大于70就报警

#!/bin/bash
sensors |awk '{print $3}' |egrep '^\+' |sed  's/\+//' |while read temp
do
        if [[ $temp > 70 ]]
        then
                echo "$temp is critcal"
        else
                echo "$temp is normal"
        fi
done

   6,把此脚本放到/usr/local/nagios/libexec/check_temp.sh

[root@mail5 ~]# chmod +x /usr/local/nagios/libexec/check_temp.sh
[root@mail5 ~]# chown nagios. /usr/local/nagios/libexec/check_temp.sh

   7,添加nrpe.cfg配置

command[check_temp]=/usr/local/nagios/libexec/check_temp.sh

   8,重启服务

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

   9,服务端配置

define service{
        use                     generic-service
        host_name               mail_21
        service_description     check-temp
        check_command           check_nrpe!check_temp
        }

   10,检测nagios,并重启nagios服务

[root@Leser01 services]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@Leser01 services]# /etc/init.d/nagios restart

   11,检测脚本是否正常

[root@Leser01 services]# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.21 -c check_temp
36.0°C is normal
31.0°C is normal
36.0°C is normal
31.0°C is normal
36.0°C is normal
38.0°C is normal
41.0°C is normal
38.0°C is normal

   

你可能感兴趣的:(监控服务器CPU温度)