用MRTG监控CPU温度
夏天马上就来临了~相信很多人都人都关心自己的CPU会不会因为温度过高而罢工呢?那Linux底下有没有可以监测温度的软件哩?
那就是lm-sensor。那该如何安装呢?
如果你的核心版本是2.2.X
请下载i2c和lm-sensor二个套件
如果你的核心版本是2.4.X
只需要下载lm-sensor就可以了
为了套件管理的方便我把这二个档案都放在/usr/local/src底下
注:如果要让i2c也可以在其它核心版本执行行,要把它编成模块,后面会有解说。
- root# cd /usr/local/src
- root# tar zxvfp lm_sensors-2.8.0.tar.gz
- root# tar zxvfp i2c-2.8.0.tar.gz
- root# cd /usr/local/src/i2c-2.8.0
- root# make clean <<<--- 很重要,这样才不会有编译不完全
- root# make dep
- root# make all
- root# make install
这样就把ic2给装好啦接着装lm-sensor吧
- root#cd /usr/local/src/lm_sensors-2.8.0
- root#make clean (和上面一样,一定要做这个步骤喔 )
- root#make dep
- root#make all
- root#make install
这样连lm-sensor都装好啦简单吧
- root# /sbin/depmod -a
修改底下这个档案把函数库加载
- root# vi /etc/ld.so.conf
- /usr/local/lib 加入这一行
- root# ldconfig
- root#./prog/mkdev/mkdev.sh 产生驱动程序以支持要侦测的东西
- root#sensors-detect 扫瞄你的主机使用那些芯片组
只要一直按Enter就好了,照它的默认值就好等到底下的东西跑出来
- #----cut here----
- # I2C adapter drivers
- modprobe i2c-isa
- # I2C chip drivers
- modprobe w83781d
- modprobe sis5595
- #----cut here----
- To make the sensors modules behave correctly, add these lines to either
- /etc/modules.conf or /etc/conf.modules:
- #----cut here----
- # I2C module options
- alias char-major-89 i2c-dev
- #----cut here----
- root#vi /etc/modules.conf
- alias char-major-89 i2c-dev 把这行加进去,开机就会加载了
- root#modprobe i2c-isa
- root#modprobe w83781d
- root#modprobe sis5595
把上面叁个加载
- root#sensors
- w83697hf-isa-0290
- Adapter: ISA adapter
- Algorithm: ISA algorithm
- VCore: +1.47 V (min = +0.00 V, max = +0.00 V) ALARM
- +3.3V: +3.34 V (min = +2.97 V, max = +3.63 V)
- +5V: +5.12 V (min = +4.50 V, max = +5.48 V)
- +12V: +11.67 V (min = +10.79 V, max = +13.11 V)
- -12V: -11.83 V (min = -13.21 V, max = -10.90 V)
- -5V: +3.53 V (min = -5.51 V, max = -4.51 V) ALARM
- V5SB: +5.58 V (min = +4.50 V, max = +5.48 V)
- VBat: +3.15 V (min = +2.70 V, max = +3.29 V)
- fan1: 3970 RPM (min = 3000 RPM, div = 2)
- fan2: 0 RPM (min = 3000 RPM, div = 2) ALARM
- temp1: +40°C (limit = +60°C) sensor = thermistor
- temp2: +39.5°C (limit = +60°C, hysteresis = +50°C) sensor = PII/Celeron diode
- alarms: Chassis intrusion detection ALARM
- beep_enable:
- Sound alarm disabled
- sis5595-isa-8008
- Adapter: ISA adapter
- Algorithm: ISA algorithm
- VCore 1: +4.08 V (min = +4.08 V, max = +4.08 V) ALARM
- VCore 2: +4.08 V (min = +4.08 V, max = +4.08 V) ALARM
- +3.3V: +4.08 V (min = +4.08 V, max = +4.08 V) ALARM
- +5V: +6.85 V (min = +6.85 V, max = +6.85 V) ALARM
- fan1: 0 RPM (min = 0 RPM, div = 8) ALARM
- fan2: 0 RPM (min = 0 RPM, div = 8) ALARM
- temp: +51°C (limit = +51°C, hysteresis = +51°C) ALARM
- alarms: Board temperature input (usually LM75 chips) ALARM
如果不想每次重开机都要重新加载一次,可以把以上那些写进/etc/rc.d/rc.local里面喔
看到上面的东东跑出来之后就成功一半啰,接下来让它和MRTG整合在一起吧
- root#cd /var/www/html/mrtg
- root#mkdir temp
- root#cd temp
- root#vi mrtg.temp
档案内容如下
- #!/bin/bash
- cputemp=`sensors | grep temp1 |awk '{print $2}'|cut -c 2-4` 这句是说找出有temp1那一行,印出第二个列的2-4个字
- systemp =`sensors | grep temp2 |awk '{print $2}'|cut -c 2-4` 不用解释了吧
- UPtime=`/usr/bin/uptime | awk '{print $3 " " $4 " " $5}'`
- echo $cputemp
- echo $systemp
- echo $UPtime
- echo dc.blue-moon.idv.tw (改成你的主机名称)
- root#chmod 755 mrtg.temp 改成可执行
- root#./mrtg.temp 试试看有没有问题
再来写下面的档案
- root#vi mrtg.cfg.temp
WorkDir: /var/www/html/mrtg/temp/
Language: big5
Target[index]: `/var/www/html/mrtg/temp/mrtg.temp`
MaxBytes[index]:60
Options[index]: gauge, nopercent, growright
YLegend[index]: Temp (度)
ShortLegend[index]: 度
LegendO[index]: 系统温度;
LegendI[index]: CPU温度;
Title[index]: Blue-Moon City 系统温度表
PageTop[index]:
Blue-Moon City 主机温度表
系统: RedHat 9.0+Apache 2.0.40
这样只要连到就可以连到,不用再打档名了
- root#/usr/bin/mrtg /var/www/html/mrtg/temp/mrtg.cfg.temp
执行三次
再把它放入排程
- root#vi /etc/crontab
- */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/temp/mrtg.cfg.temp > /dev/null 2>&1
这样,使用MRTG监控CPU温度就大功告成啦!
【编辑推荐】