徐々にLinuxというものをわかり始めてきたので自己解決率も若干上がってきた気がする今日この頃。
前回CPU周波数の取得を行うよう設定したが、今度はZabbixにてCPU温度を取得できるようにしようと思う。これから来る夏に向けて割と重要な作業かもしれない。
何故なら、当方のサーバーがある部屋は、非常に日当たりが良好であるからだ。
<2014/07/15 作業手順変更につき、最新記事参照を推奨します。>
>>yum install lm_sensors
を実行し、インストール。
>>sensors-detect
コマンドを実行し、テキトーにYESを入力していき、サーバーを再起動させる。
>>sensors
apcitz-virtual-0
Adapter: Virtual device
temp1: +27.8℃ (high = +82.0℃, crit = +103.0℃)
temp2: +29.8℃ (high = +82.0℃, crit = +103.0℃)
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +29.0℃ (high = +82.0℃, crit = +102.0℃)
Core 0: +26.0℃ (high = +82.0℃, crit = +102.0℃)
Core 1: +29.0℃ (high = +82.0℃, crit = +102.0℃)
と表示された。取得は問題ないようなので次のステップ
# sensors -u
acpitz-virtual-0000
Adapter: Virtual device
temp1:
temp1_input: 27.800
temp1_crit: 103.000
temp2:3_max: 82.000
temp2_input: 29.800
temp2_crit: 103.000.000
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:
temp1_input: 30.000
temp1_max: 82.000
temp1_crit: 102.000
temp1_crit_alarm: 0.000
Core 0:
temp2_input: 25.000
temp2_max: 82.000
temp2_crit: 102.000
temp2_crit_alarm: 0.000
Core 1:
temp3_input: 30.000
temp3_max: 82.000
temp3_crit: 102.000
temp3_crit_alarm: 0.000
temp2_inputとtemp3_inputが今回対象なのだが、このままでは問題がある。
temp2_inputが2つ存在する。
このままgrepで抽出を行っても2つの項目が抽出されてしまう。
#sensors -u |grep temp2_input
temp2_input: 29.800
temp2_input: 25.000
もちろん使いたいのは2行目にある方である。なので検索する文字列をダブらない、【Core】に変更してしまう。その際に、【-A1】オプションを追加して検索結果表示を広げてしまう。
♯sensors -u |grep -A1 Core
Core 0:
temp2_input: 25.000
—
Core 1:
temp3_input: 30.000
この検索結果自体にさらにgrepコマンドを投げてさらに絞り込ませる。
♯sensors -u |grep -A1 Core |grep temp2_input
temp2_input: 27.000
取り出しに成功したが、色々不要な文字列が多いのでそれも除去する。
♯sensors -u |grep -A1 Core |grep temp2_input |cut -d “:” -f2 |cut -d ” ” -f2
27.000
これで出力コマンドはほぼ完成しただろう・・・。
あとはzabbix-agentにユーザーパラメータとして実装すればよさそう。
UserParameter=cpu.temp[*],sensors -u |grep -A1 Core |grep temp$1_input |cut -d “:” -f2 |cut -d ” ” -f2
とりあえずここまで。動作確認はまた後ほど追記という形で!