如何使用MRTG監(jiān)控CPU溫度
用MRTG監(jiān)控CPU溫度
夏天馬上就來臨了~相信很多人都人都關(guān)心自己的CPU會(huì)不會(huì)因?yàn)闇囟冗^高而罷工呢?那Linux底下有沒有可以監(jiān)測溫度的軟件哩?
那就是lm-sensor。那該如何安裝呢?
如果你的核心版本是2.2.X
請下載i2c和lm-sensor二個(gè)套件
如果你的核心版本是2.4.X
只需要下載lm-sensor就可以了
為了套件管理的方便我把這二個(gè)檔案都放在/usr/local/src底下
注:如果要讓i2c也可以在其它核心版本執(zhí)行行,要把它編成模塊,后面會(huì)有解說。
- 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 <<<--- 很重要,這樣才不會(huì)有編譯不完全
- 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 (和上面一樣,一定要做這個(gè)步驟喔 )
- root#make dep
- root#make all
- root#make install
這樣連lm-sensor都裝好啦簡單吧
- root# /sbin/depmod -a
修改底下這個(gè)檔案把函數(shù)庫加載
- root# vi /etc/ld.so.conf
- /usr/local/lib 加入這一行
- root# ldconfig
- root#./prog/mkdev/mkdev.sh 產(chǎn)生驅(qū)動(dòng)程序以支持要偵測的東西
- root#sensors-detect 掃瞄你的主機(jī)使用那些芯片組
只要一直按Enter就好了,照它的默認(rèn)值就好等到底下的東西跑出來
- #----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 把這行加進(jìn)去,開機(jī)就會(huì)加載了
- root#modprobe i2c-isa
- root#modprobe w83781d
- root#modprobe sis5595
把上面叁個(gè)加載
- 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
如果不想每次重開機(jī)都要重新加載一次,可以把以上那些寫進(jìn)/etc/rc.d/rc.local里面喔
看到上面的東東跑出來之后就成功一半啰,接下來讓它和MRTG整合在一起吧
- root#cd /var/www/html/mrtg
- root#mkdir temp
- root#cd temp
- root#vi mrtg.temp
檔案內(nèi)容如下
- #!/bin/bash
- cputemp=`sensors | grep temp1 |awk '{print $2}'|cut -c 2-4` 這句是說找出有temp1那一行,印出第二個(gè)列的2-4個(gè)字
- 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 (改成你的主機(jī)名稱)
- root#chmod 755 mrtg.temp 改成可執(zhí)行
- 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]: 系統(tǒng)溫度;
LegendI[index]: CPU溫度;
Title[index]: Blue-Moon City 系統(tǒng)溫度表
PageTop[index]:
Blue-Moon City 主機(jī)溫度表
系統(tǒng): RedHat 9.0+Apache 2.0.40
這樣只要連到就可以連到,不用再打檔名了
- root#/usr/bin/mrtg /var/www/html/mrtg/temp/mrtg.cfg.temp
執(zhí)行三次
再把它放入排程
- root#vi /etc/crontab
- */5 * * * * root /usr/bin/mrtg /var/www/html/mrtg/temp/mrtg.cfg.temp > /dev/null 2>&1
這樣,使用MRTG監(jiān)控CPU溫度就大功告成啦!
【編輯推薦】