>> HOME >> CentOS 4 MENU >> MRTG サーバー監視システム 2 (CPU/SYSTEM温度 CPU冷却ファン回転数)
障害の兆候を見逃さないために、NET-SNMP と MRTGを利用してサーバーの状況を外部から監視できるようにします。
今回は、各種ハードウェアセンサ ( CPU/System温度、CPU冷却ファン回転数 ) の値を監視しますので、システムの状態 ( CPUの温度や FANの回転数 ) などを表示するコマンドラインツール Lm_sensors を使用し、SNMP にて監視できるようにして、MRTG を用いてグラフを自動生成するようにします。と言うことで、追加する監視する項目は
  • CPU/SYSTEM 温度
  • CPU 冷却ファン回転数

 1. Lm_sensors の設定
1 ) Lm_sensors の設定コマンド sensors-detect 実行
2 ) Lm_sensors 設定ファイル /etc/modules.conf の編集
3 ) Lm_sensors 自動起動設定
 2. サーバーの再起動
 3. Lm_sensors 設定確認
 4. NET-SNMP 監視手続き
1 ) CPUファン回転数、CPU/System温度を取得するスクリプトの作成
2 ) NET-SNMP 設定ファイル /etc/snmp/snmpd.conf の編集
3 ) NET-SNMP 再起動
4 ) MRTG 設定ファイル /etc/mrtg/mrtg.cfg の編集
 5. MRTG の監視ページ作成
1 ) MRTG の監視ページ作成実行
2 ) MRTG のインデックスページ作成
1. Lm_sensors の設定
1 ) Lm_sensors の設定コマンド sensors-detect 実行
[root@linux ~]# sensors-detect 

This program will help you determine which I2C/SMBus modules you need to
load to use lm_sensors most effectively. You need to have i2c and
lm_sensors installed before running this program.
Also, you need to be `root', or at least have access to the /dev/i2c-*
files, for most things.
If you have patched your kernel and have some drivers built in, you can
safely answer NO if asked to load some modules. In this case, things may
seem a bit confusing, but they will still work.

It is generally safe and recommended to accept the default answers to all
questions, unless you know what you're doing.

 We can start with probing for (PCI) I2C or SMBus adapters.
 You do not need any special privileges for this.
 Do you want to probe now? (YES/no): n 

As you skipped adapter detection, we will only scan already loaded
adapter modules.
If you have undetectable or unsupported adapters, you can have them
scanned by manually loading the modules before running this script.

 To continue, we need module `i2c-dev' to be loaded.
 If it is built-in into your kernel, you can safely skip this.
 i2c-dev is not loaded. Do you want to load it now? (YES/no): n 
 Well, you will know best. We will just hope you edited `/etc/modprobe.conf'
 for automatic loading of this module. If not,
 you won't be able to open any /dev/i2c-* file (unless youhave it built-in
 into your kernel)

 We are now going to do the adapter probings. Some adapters may hang halfway
 through; we can't really help that. Also, some chips will be double detected;
 we choose the one with the highest confidence value in that case.
 If you found that the adapter hung after probing a certain address, you can
 specify that address to remain unprobed. That often
 includes address 0x69 (clock chip).

Some chips are also accessible through the ISA bus. ISA probes are
typically a bit more dangerous, as we have to write to I/O ports to do
this. This is usually safe though.

Do you want to scan the ISA bus? (YES/no): y 
Probing for `National Semiconductor LM78'
  Trying address 0x0290... Failed!
Probing for `National Semiconductor LM78-J'
  Trying address 0x0290... Failed!
Probing for `National Semiconductor LM79'
  Trying address 0x0290... Failed!
Probing for `Winbond W83781D'
  Trying address 0x0290... Failed!
Probing for `Winbond W83782D'
  Trying address 0x0290... Failed!
Probing for `Winbond W83627HF'
  Trying address 0x0290... Failed!
Probing for `Winbond W83627EHF'
  Trying address 0x0290... Failed!
Probing for `Winbond W83697HF'
  Trying address 0x0290... Failed!
Probing for `Silicon Integrated Systems SIS5595'
  Trying general detect... Failed!
Probing for `VIA Technologies VT82C686 Integrated Sensors'
  Trying general detect... Success!
    (confidence 9, driver `via686a')
Probing for `VIA Technologies VT8231 Integrated Sensors'
  Trying general detect... Failed!
Probing for `ITE IT8712F'
  Trying address 0x0290... Failed!
Probing for `ITE IT8705F / SiS 950'
  Trying address 0x0290... Failed!
Probing for `IPMI BMC KCS'
  Trying address 0x0ca0... Failed!
Probing for `IPMI BMC SMIC'
  Trying address 0x0ca8... Failed!

Some Super I/O chips may also contain sensors. Super I/O probes are
typically a bit more dangerous, as we have to write to I/O ports to do
this. This is usually safe though.

Do you want to scan for Super I/O sensors? (YES/no): n 

 Now follows a summary of the probes I have just done.
 Just press ENTER to continue: 

Driver `via686a' (should be inserted):
  Detects correctly:
  * ISA bus, undetermined address (Busdriver `i2c-isa')
Hint: Try forcing the chip address. Consult the documentation
of particular chip for details and address value.
    Chip `VIA Technologies VT82C686 Integrated Sensors' (confidence: 9)


 I will now generate the commands needed to load the I2C modules.
 Sometimes, a chip is available both through the ISA bus and an I2C bus.
 ISA bus access is faster, but you need to load an additional driver module
 for it. If you have the choice, do you want to use the ISA bus or the
 I2C/SMBus (ISA/smbus)? I 

To make the sensors modules behave correctly, add these lines to
/etc/modprobe.conf:

# /etc/modules.conf に追記しますのでメモしておきます。※
#----cut here----
# I2C module options
alias char-major-89 i2c-dev
#----cut here----

To load everything that is needed, add this to some /etc/rc* file:

# /etc/rc.local に追記しますのでメモしておきます。※
#----cut here----
# I2C adapter drivers
modprobe i2c-isa
# I2C chip drivers
modprobe via686a
# sleep 2 # optional
/usr/bin/sensors -s # recommended
#----cut here----

WARNING! If you have some things built into your kernel, the list above
will contain too many modules. Skip the appropriate ones! You really should
try these commands right now to make sure everything is working properly.
Monitoring programs won't work until it's done.

Do you want to generate /etc/sysconfig/lm_sensors? (YES/no): y 
Copy prog/init/lm_sensors.init to /etc/rc.d/init.d/lm_sensors
for initialization at boot time.
2 ) Lm_sensors 設定ファイル /etc/modules.conf の編集
[root@linux ~]# vi /etc/modules.conf 

# 先ほどの※,鮑埜紊膨媛
# I2C module options
alias char-major-89 i2c-dev
3 ) Lm_sensors 自動起動設定
[root@linux ~]# vi /etc/rc.local 

# 先ほどの※△鮑埜紊膨媛
modprobe i2c-isa
# I2C chip drivers
modprobe via686a
# sleep 2 # optional
/usr/bin/sensors -s # recommended
2. サーバーの再起動
[root@linux ~]# shutdown -r now 
3. Lm_sensors 設定確認
sensors コマンドにより、センサー一覧を表示させます。
[root@linux ~]# sensors 
via686a-isa-0c00
Adapter: ISA adapter
CPU core:  +1.47 V  (min =  +0.06 V, max =  +3.10 V)
+2.5V:     +1.16 V  (min =  +2.37 V, max =  +2.62 V)   ALARM
I/O:       +3.31 V  (min =  +3.13 V, max =  +3.47 V)
+5V:       +5.05 V  (min =  +4.51 V, max =  +5.50 V)
+12V:     +12.12 V  (min = +10.81 V, max = +13.20 V)
# CPU ファン回転数
CPU Fan:  4218 RPM  (min =  685 RPM, div = 8)
P/S Fan:     0 RPM  (min =  756 RPM, div = 8)
# SYSTEM 温度
SYS Temp:  +54.0°C  (high =   +45°C, hyst =   +40°C)   ALARM
# CPU 温度
CPU Temp:  +38.2°C  (high =   +60°C, hyst =   +55°C)
SBr Temp:  +25.4°C  (high =   +65°C, hyst =   +60°C)
4. NET-SNMP 監視手続き
1 ) CPUファン回転数、CPU/System温度を取得するスクリプトの作成
Lm_sensors の設定確認で表示された値のうち、取得すべき値は、8行目と、10、11行目であることが分かります。
従いまして、これら行を取得し、更に、MRTG は整数値しか受け取りませんので、その値を切り取り、整形します。
[root@linux ~]# vi /usr/local/bin/sensor4mrtg 

#!/bin/sh

/usr/bin/sensors via686a-isa-0c00 | \
/usr/bin/awk '{if ((8 == NR) || ((10 <= NR ) && (NR <= 12))) print $3}' | \
/bin/sed -e 's/+//' -e 's/[^0-9].*//'


[root@linux ~]# chmod +x /usr/local/bin/sensor4mrtg 
2 ) NET-SNMP 設定ファイル /etc/snmp/snmpd.conf の編集
[root@linux ~]# vi /etc/snmp/snmpd.conf 

# Other ideas:
#
# exec .1.3.6.1.4.1.2021.51 ps /bin/ps
# exec .1.3.6.1.4.1.2021.52 top /usr/local/bin/top
# exec .1.3.6.1.4.1.2021.53 mailq /usr/bin/mailq
# 以下を追加
exec .1.3.6.1.4.1.2021.53 sensors /usr/local/bin/sensor4mrtg
3 ) NET-SNMP 再起動
[root@linux ~]# service snmpd restart 
snmpd を停止中:                                            [  OK  ]
snmpd を起動中:                                            [  OK  ]
4 ) MRTG 設定ファイル /etc/mrtg/mrtg.cfg の編集
[root@linux ~]# vi /etc/mrtg/mrtg.cfg 

# 以下を全行追加
### CPU/System Temperature ####
Target[temp-cpu]: 1.3.6.1.4.1.2021.53.101.3&1.3.6.1.4.1.2021.53.101.2:public@192.168.1.11
MaxBytes[temp-cpu]: 80
Options[temp-cpu]: gauge, absolute, growright, nopercent, noinfo
YLegend[temp-cpu]: Temperature ( ℃)
ShortLegend[temp-cpu]: ℃
Legend1[temp-cpu]: CPU
Legend2[temp-cpu]: System
LegendI[temp-cpu]: CPU
LegendO[temp-cpu]: System
Title[temp-cpu]: CPU & System 温度
PageTop[temp-cpu]: <H1>CPU & System 温度</H1>

### FAN RPM ####
Target[fan-speed]: 1.3.6.1.4.1.2021.53.101.1&1.3.6.1.4.1.2021.53.101.1:public@192.168.1.11
MaxBytes[fan-speed]: 6000
Options[fan-speed]: gauge, absolute, growright, nopercent, noinfo
YLegend[fan-speed]: rpm (rpm)
ShortLegend[fan-speed]: rpm
Legend1[fan-speed]: Fan Speed
Legend2[fan-speed]: Fan Speed
LegendI[fan-speed]: Fan Speed
LegendO[fan-speed]: Fan Speed
Title[fan-speed]: Fan Speed (rpm)
PageTop[fan-speed]: <H1>Fan Speed (rpm)</H1>
5. MRTG の監視ページ作成
1 ) MRTG の監視ページ作成実行
MRTG を実行し、MRTG による監視の閲覧ページを作成します。
MRTG は過去2回起動時のログを使用するため、初回起動から2回目までは必ず WARNING が出るので、MRTGの実行を3回行います。また、mrtg.cfg 修正後も、MRTGの実行を3回行う方がいいでしょう。
[root@linux ~]# mrtg /etc/mrtg/mrtg.cfg 
Rateup WARNING: /usr/bin/rateup Can't remove temp-cpu.old updating log file
Rateup WARNING: /usr/bin/rateup Can't remove fan-speed.old updating log file

[root@linux ~]# mrtg /etc/mrtg/mrtg.cfg 
Rateup WARNING: /usr/bin/rateup Can't remove temp-cpu.old updating log file

[root@linux ~]# mrtg /etc/mrtg/mrtg.cfg 
MRTG の各監視ページは以下に作成されます。
CPU / SYSTEM 温度状況監視確認
http://mountainbigroad.jp/mrtg/temp-cpu.html
CPU 冷却ファン回転数監視確認
http://mountainbigroad.jp/mrtg/fan-speed.html
2 ) MRTG のインデックスページ作成
各監視画面を統合したような見出しページを、MRTG 検出結果格納先ディレクトリ(WorkDir)に作成します。
[root@linux ~]# indexmaker --columns=1 --title="サーバ監視システム" \
--addhead="<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=euc-jp\">" \
/etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html