HDDの温度監視ツール smartctlの導入
sorry Japanese only
最終更新日 2006/08/21
page size = Mbyte

windows用ツールを探しにきた方はこちら => CPU温度計ページ
windows用のソフトをお探しの方はこちら => VECTORのハードウェアー
linux PC全般のサンプル表示はこちら => rrdtoolページ

HDDの温度を見るツールが linux用もあるというのを知り導入してみました。

こんなグラフが出来上がります。


以下はこのグラフを作るまでの方法です。(linux用です)

smartmontools Home Pageより downloadします。
smartsuite package(ver2.1)というのではなく、Install from the source tarballと書かれた見出しのリンク先より downloadした方が良いです。
私が downloadした verは 5.32でした。

downloadしたら
gzip -d
tar xvf
configure
make
make install

と実行しますが、出来上がったバイナリを /usr/local/sbinとか変な所へ入れるのはやめて欲しい・・・

で、実行するとこんな画面になります。
Winにて IDE HDDの SMART情報を表示させるツールに比べると、表示される情報が随分と違っていますが、
これはこれで楽しめる情報です。

[root]#smartctl -a /dev/sda
smartctl version 5.32 Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

Device: SEAGATE  ST336607LW       Version: 0007
Serial number: 3JA7Z7Y70000744978NE
Device type: disk
Transport protocol: Parallel SCSI (SPI-4)
Local Time is: Mon Aug  2 20:08:07 2004 JST
Device supports SMART and is Enabled
Temperature Warning Enabled
SMART Health Status: OK

Current Drive Temperature:     34 C
Drive Trip Temperature:        68 C
Vendor (Seagate) cache information
  Blocks sent to initiator = 2318344
  Blocks received from initiator = 93959808
  Blocks read from cache and sent to initiator = 1090338
  Number of read and write commands whose size <= segment size = 3275813
  Number of read and write commands whose size > segment size = 68112
Vendor (Seagate) factory information
  number of hours powered up = 48.83
  number of minutes until next internal SMART test = 110

Error counter log:
          Errors Corrected    Total      Total   Correction     Gigabytes    Total
              delay:       [rereads/    errors   algorithm      processed    uncorrected
            minor | major  rewrites]  corrected  invocations   [10^9 bytes]  errors
read:       2103        0         0      2103       2103          7.169           0
write:         0        0         0         0          0         31.110           0

Non-medium error count:        0

[GLTSD (Global Logging Target Save Disable) set. Enable Save with '-S on']

SMART Self-test log
Num  Test              Status                 segment  LifeTime  LBA_first_err [SK ASC ASQ]
     Description                              number   (hours)
# 1  Background short  Completed                   -     0                   - [-   -    -]
# 2  Background short  Completed                   -     0                   - [-   -    -]

Long (extended) Self Test duration: 768 seconds [12.8 minutes]

数日前から稼働しているチーちゃん 10k6、minorなエラーがカウントされていますが、大丈夫でしょうか・・・
その後の経過はこちら
2004/11/21 約3ヶ月後 => smartctl_20041121.txt
2005/04/22 win2000のパソコンで使っていたチーちゃん 15k3が linux機にお下がりで回ってきました => smartctl_15k3_20050422.txt
1年後 2006/08/17

この中にある『 Current Drive Temperature: 34 C 』を rrdtoolで記録してグラフを書かせよう!
ってことで、どうせなら mbmonにて書かせている CPUと CASE温度も、今回書かせる HDD温度と一緒のグラフに統一して・・

と言うことで以下に続きます。

rrdファイルの作成

CPU温度,CASE温度,HDD温度の 3つを 1個の rrdファイルへ記録するよう rrdtool createにて rrdファイルを作成します。

rrdtool create sensor-temp.rrd \
 -b N \
 --step 300 \
 DS:CPU:GAUGE:600:-100:200 \
 DS:CASE:GAUGE:600:-100:200 \
 DS:10K6:GAUGE:600:-100:200 \
 RRA:MIN:0.1:12:8760 \
 RRA:MAX:0.1:12:8760 \
 RRA:LAST:0.1:1:288000

1行目から説明すると

rrdtool create sensor-temp.rrd
ファイル名は sensor-temp.rrdというファイルを作成

-b N
N(現在時刻)より databaseを作る

--step 300
300秒ごとに rrdファイルの中に dataを記録していく。
rrdtool updateにて 1秒ごとに記録しようがなんだろうが --step 300だと、300秒ごとに 1個記録されていきます。
1秒ごとに 300回更新したら、300個の平均を取って 1個記録します。

DS:CPU:GAUGE:600:-100:200
CPUという名前で記録するデーターは、
GAUGE 前後に繋がりのないデーター(って言い方で良いのかな)
600 600秒更新されなかったら unknownデーターとする
-100:200 rrdtool update時に -100〜200の間に入っているデーターのみを使用する。

DS:CASE:GAUGE:600:-100:200
CPUと同じ。
DS:に続けて何個も書いていくことにより、一つの rrdファイルに何個もデーターを格納できるようになる。

RRA:MIN:0.1:12:8760
記録していったデーターの中から、MIN(最小値)のみの記録を 300秒の 12回分 に 1回ずつ (1時間に 1回)記録していく。
これを 8760個 (1時間を 8760個だから 8760=24時間*365日 1年分記録を残すと言うこと)

RRA:LAST:0.1:1:288000
記録していったデーターの中から、LAST(現在値)の記録は 300秒に 1回ずつ 288000個記録していく。
288000事言うことは、300秒*288000/60秒/60分/24時間=1000日分記録を残すと言うこと。

このようにして作成した rrdファイルに、以下の shスクリプトで CPU,CASE,HDDの温度を記録していきます。
#!/bin/bash
#

#環境変数セット
#
rrddir="/usr/local/HotSaNIC/modules/sensors/rrd"
rrdbin="/usr/local/rrdtool/bin/rrdtool"
mbmbin="/usr/local/bin/mbmon"
smabin="/usr/local/bin/smartctl"

#各種 data取得
#
current_time=`perl -e 'print time'`
case_temp=`/usr/local/bin/mbmon -T1 -c 1 | sed -e s/\ //g`          *注1
cpu_temp=`$mbmbin -T2 -c 1 | sed -e s/\ //g`
hdd_temp=`$smabin -A /dev/sda|grep Current|awk '{print $4}'|sed -e s/\ //g` 
#smartctl ver5.36では以下のように変更する
#hdd_temp=`$smabin -A /dev/sda|grep "Current Drive"|awk '{print $4}'|sed -e s/\ //g` 


#rrdファイル更新
#
$rrdbin update $rrddir/sensor-temp.rrd $current_time:$cpu_temp:$case_temp:$hdd_temp
*注1
rrdtool updateを行うとき、以下のようにスペースが入っていると update失敗します。
20.0: 9.0:20
部屋の温度が寒くなって 10度を下回ると、updateできずに Data unknownになってしまっていたので気が付きました。
それぞれの温度の出力からスペースをカットするコマンド
sed -e s/\ //g
を付け加えました。


あとはグラフを書かせるスクリプトですが、こんな感じのを作りました。=> sensor-graph-output.sh
このスクリプト一つで hour,day,week,month,yearのグラフを作ってしまっていますが、yearを hourと同じペースで作る必要もないんで、分割するなりした方が負荷は減ると思います。

と言うことで、実際には hourのみ別ファイルにして 6分おきに作成。
その他は 1時間おきに作成
このような cronで実行しています。
[root]# crontab -l
*/4 * * * * /usr/local/HotSaNIC/modules/sensors/sensor-temp-update.sh
*/6 * * * * /usr/local/HotSaNIC/modules/sensors/sensor-graph-output-hour.sh
2 * * * * /usr/local/HotSaNIC/modules/sensors/sensor-graph-output-day.sh
*/4 4分おき
*/6 6分おき
2 毎時 2分の時に実行

51562
戻る