1、安装硬件传感器监控软件sensors
yum install -y lm_sensors*

2、运行sensors-detect进行传感器检测
##一路回车即可

Do you want to overwrite /etc/sysconfig/lm_sensors? (YES/no): 
Starting lm_sensors: loading module coretemp               [  OK  ]
Unloading i2c-dev... OK

3、运行sensors看是否能读取数据,如下像下面这样表示正常
# sensors
coretemp-isa-0000
Adapter: ISA adapter
ERROR: Can't get value of subfeature temp1_input: Can't read
Physical id 0:  +0.0°C  (high = +100.0°C, crit = +100.0°C)  
ERROR: Can't get value of subfeature temp2_input: Can't read
Core 0:         +0.0°C  (high = +100.0°C, crit = +100.0°C)  
ERROR: Can't get value of subfeature temp3_input: Can't read
Core 1:         +0.0°C  (high = +100.0°C, crit = +100.0°C)

coretemp-isa-0002
Adapter: ISA adapter
ERROR: Can't get value of subfeature temp1_input: Can't read
Physical id 1:  +0.0°C  (high = +100.0°C, crit = +100.0°C)  
ERROR: Can't get value of subfeature temp2_input: Can't read
Core 0:         +0.0°C  (high = +100.0°C, crit = +100.0°C)  
ERROR: Can't get value of subfeature temp3_input: Can't read
Core 1:         +0.0°C  (high = +100.0°C, crit = +100.0°C)

4、添加监控脚本vim /usr/local/nagios/libexec/check_cputemp

#!/bin/sh
#########check_cputemp###########
#date : May 2013
#Licence GPLv2
#by Barlow
#/usr/local/nagios/libexec/check_cputemp
#you can use NRPE to define service in nagios
#check_nrpe!check_cputemp
# Plugin return statements
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
print_help_msg(){
$Echo "Usage: $0 -h to get help."
}
print_full_help_msg(){
$Echo "Usage:"
$Echo "$0 [ -v ] -m sensors -w cpuT -c cpuT"
$Echo "Sepicify the method to use the temperature data sensors."
$Echo "And the corresponding Critical value must greater than Warning value."
$Echo "Example:"
$Echo "${0} -m sensors -w 40 -c 50"
}
print_err_msg(){
$Echo "Error."
print_full_help_msg
}
to_debug(){
if [ "$Debug" = "true" ]; then
$Echo "$*" >> /var/log/check_sys_temperature.log.$$ 2>&1
fi
}
unset LANG
Echo="echo -e"
if [ $# -lt 1 ]; then
print_help_msg
exit 3
else
while getopts :vhm:w:c: OPTION
do
case $OPTION
in
v)
#$Echo "Verbose mode."
Debug=true
;;
m)
method=$OPTARG
;;
w)
WARNING=$OPTARG
;;
c)
CRITICAL=$OPTARG ;;
h)
print_full_help_msg
exit 3
;;
?)
$Echo "Error: Illegal Option."
print_help_msg
exit 3
;;
esac
done
if [ "$method" = "sensors" ]; then
use_sensors="true"
to_debug use_sensors
else
$Echo "Error. Must to sepcify the method to use sensors."
print_full_help_msg
exit 3
fi
to_debug All Values  are \" Warning: "$WARNING" and Critical: "$CRITICAL" \".
fi
#########lm_sensors##################
if [ "$use_sensors" = "true" ]; then
sensorsCheckOut=`which sensors 2>&1`
if [ $? -ne 0 ];then
echo $sensorsCheckOut
echo Maybe you need to check your sensors.
exit 3
fi
to_debug Use $sensorsCheckOut to check system temperature
TEMP1=`sensors | head -3 | tail -1 | gawk '{print $3}' | grep -o [0-9][0-9]`
TEMP2=`sensors | head -4 | tail -1 | gawk '{print $3}' | grep -o [0-9][0-9]`
TEMP3=`sensors | head -5 | tail -1 | gawk '{print $3}' | grep -o [0-9][0-9]`
TEMP4=`sensors | head -6 | tail -1 | gawk '{print $3}' | grep -o [0-9][0-9]`
##温度的取数根据你cpu的核数确定,我的是四核,所以取TEMP1-4个CPU温度数并计算平均值
SUM=$(( $TEMP1 + $TEMP2 + $TEMP3 + $TEMP4 ))
TEMP=$(($SUM/4))
if [ -z "$TEMP" ] ; then
$Echo "No Data been get here. Please confirm your ARGS and re-check it with Verbose mode, then to check the log."
exit 3
fi
to_debug temperature data is $TEMP
else
$Echo "Error. Must to sepcify the method to use sensors"
print_full_help_msg
exit 3
fi
######### Comparaison with the warnings and criticals thresholds given by user############
CPU_TEMP=$TEMP
#if [ "$WARNING" != "0" ] || [ "$CRITICAL" != "0" ]; then
if [ "$CPU_TEMP" -gt "$CRITICAL" ]  && [ "$CRITICAL" != "0" ]; then
STATE="$STATE_CRITICAL"
STATE_MESSAGE="CRITICAL"
to_debug $STATE , Message is $STATE_MESSAGE
elif [ "$CPU_TEMP" -gt "$WARNING" ] && [ "$WARNING" != "0" ]; then
STATE="$STATE_WARNING"
STATE_MESSAGE="WARNING"
to_debug $STATE , Message is $STATE_MESSAGE
else
STATE="$STATE_OK"
STATE_MESSAGE="OK"
to_debug $STATE , Message is $STATE_MESSAGE
fi
##返回值中注意要包含性能数据,即采用|分隔的后半部数据,且数据单位不能包含中文,否则使用PNP等绘图软件无法正常绘图。
echo "The TEMPERATURE "$STATE_MESSAGE" "-" The CPU's Temperature is "$CPU_TEMP" ℃ ! | 温度=`echo $CPU_TEMP`Celsius;$WARNING;$CRITICAL"
exit $STATE

5、赋予脚本执行权限:
chmod +x /usr/local/nagios/libexec/check_cputemp

6、配置vim /usr/local/nagios/etc/nrpe.cfg,添加如下一行:
echo "command[check_cputemp]=/usr/local/nagios/libexec/check_cputemp -m sensors -w 38 -c 45" >>/usr/local/nagios/etc/nrpe.cfg

重新启动客户端nrpe服务
-w 表示警告值,-c表示关键(紧急)值,自行根据实际情况调整
注意:以上六步均在被监控机上完成。

在客户端测试是否ok,虚拟机测试不成功,需要在物理机上实现
# /usr/local/nagios/libexec/check_cputemp -m sensors -w 38 -c 45
The TEMPERATURE OK - The CPU's Temperature is 14 ℃ ! | 温度=14Celsius;38;45
服务端执行测试:
/usr/local/nagios/libexec/check_nrpe -H 192.168.8.93 -c check_cputemp

7、在Nagios服务端配置服务:
define service{
use             generic-service
host_name需要被监控的hostname
service_description CPU Temperature
check_command check_nrpe!check_cputemp
}

保存后重启nagios服务

转载于:https://www.cnblogs.com/reblue520/p/6239760.html

nagios系列(六)之nagios实现对服务器cpu温度的监控相关推荐

  1. python监控服务器cpu温度实例_监控HP服务器CPU温度的脚本

    监控HP服务器CPU温度的脚本: #!/bin/bash Name=`hostname` IP=`/sbin/ifconfig eth0 | grep "inet addr" | ...

  2. 服务器cpu温度高日志记录位置,服务器CPU温度高

    服务器CPU温度高 内容精选 换一换 实例即云耀云服务器,是由CPU.内存.操作系统.云硬盘组成的基础的计算组件.云耀云服务器创建成功后,您就可以像使用自己的本地PC或物理服务器一样,在云上使用云耀云 ...

  3. 用Core Temp查看服务器CPU温度

    周末突然接到电话说大厦要停电30分钟,我担心空调在重新供电的时候无法自动启动,如果情况发生的话就麻烦了,必须立即回公司将机房空调启动才行.回到家后,我VPN进公司网络,想看看服务器的文档,但是发现系统 ...

  4. 怎么看服务器cpu温度命令_简单几步使用zabbix监控Linux物理服务器CPU温度

    前段时间有个属于笔者维护的小机房空调故障,温度过高导致系统卡慢,多日无人发现.于是想着使用zabbix监控CPU温度并设置告警阀值,同时也能监控到风扇异常.挡风板太脏空气不畅.进程死锁导致CPU使用率 ...

  5. zabbix监控windows服务器CPU温度

    一.准备工具 instspeedfan452.exe   --->  https://filehippo.com/zh/download_speedfan/ tail-for-windows.z ...

  6. 怎么看服务器cpu温度命令_服务器cpu温度查看

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  7. 怎么看服务器cpu温度命令_查看服务器配置信息prtdiag与systeminfo实用命令

    UNIX(SUN服务器) bash-2.05# prtdiag -v 系统配置:  Sun Microsystems  sun4u Sun Fire V890 系统时钟频率:150 MHz 内存大小: ...

  8. 服务器CPU支持普通主板,服务器CPU和服务器主板与普通的CPU和主板有什么不同?...

    服务器CPU和一般CPU的区别: 一.指令集不同 家用或者用工作用电脑配备的普通CPU,通常为CISC复杂指令集,追求指令集的大而全,尽量把各种常用的功能集成到一块,但是调用速度和命中率相比服务器CP ...

  9. 监控程序崩溃重启_第十四章 Homeassistant服务器安全及状态监控(下)

    导读: 透过对服务器CPU状态的监控,并实时发送服务器状态数据及图片来及时发现服务器异常,并在必要时解除威胁. 上篇大致说到了Linux系统的一些基础安全设定,和路由器的简单设置,虽然看似简单,却是性 ...

最新文章

  1. 【kissfft】使用kiss_fftr做FFT与iFFT
  2. 独家 | 降维是数据科学家的必由之路
  3. 一文盘点三大顶级Python库(附代码)
  4. torch.tensordot()介绍
  5. 第七章 shell学习之退出、测试、判断及操作
  6. boost shared_ptr线程安全性
  7. [Leetcode][第546题][JAVA][移除盒子][递归][动态规划]
  8. Python学习笔记,爬取笔趣阁小说
  9. 【二分法】剑指offer:二维数组中的查找
  10. react native+typescript创建移动端项目-(慕课网喜马拉雅项目笔记)-(二,导航器navigator)
  11. RayData大数据可视化教程(1)——软件使用和材质渲染基础
  12. 最新QQ勋章墙+防撤回V9.6.1版本+实测可用
  13. Pano2VR 展示全景图
  14. 数据库篇--update触发器
  15. 抖音上热门的方法和技巧
  16. envi5.3处理高分二号影像数据详细过程记录
  17. 电总协议串口调试助手
  18. 计算机应用团队,【计算机应用论文】团队合作学习下计算机应用论文(共3025字)...
  19. mysql 在当前时间上加几小时
  20. 去除图片链接边框及其链接虚线

热门文章

  1. Matlab标识指令中字符的精细控制
  2. 为什么这儿TemplateBinding不起作用了—研究WPF Binding(一)
  3. Oracle PL/SQL之Flashback Table与外键约束
  4. liunx 在虚拟机(VMware)下挂载光驱命令
  5. hdu3594 强连通 tarjan
  6. 【Android 逆向】整体加固脱壳 ( DexClassLoader 加载 dex 流程分析 | DexPathList 构造函数分析 | makeDexElements 函数分析 )
  7. 【Android 逆向】应用数据目录 ( Android 应用数据目录 /data/data/package.name | 存放 SharedPreference 的 shared_pref 目录 )
  8. 【Android 安装包优化】WebP 应用 ( 4.0 以下兼容 WebP | Android Studio 中使用 libwebp.so 库向下兼容版本 | libwebp 库测试可用性 )
  9. 【计算理论】计算理论总结 ( 正则表达式转为非确定性有限自动机 NFA | 示例 ) ★★
  10. 【计算机网络】网络安全 : 报文鉴别 ( 密码散列函数 | 报文摘要算法 MD5 | 安全散列算法 SHA-1 | MAC 报文鉴别码 )