Archive: 2014/05/26

logsensor.sh拡張

先日調達したF-PLUG(エフプラグ)

sensors.cronを拡張したので、分析スクリプト~/bin/logsensor.shも拡張する。

/var/log/sensors.logの出力は以下のようにタイムスタンプに続いて電力、照度、湿度、室温、そして行末までコア温度が並んでいるので、

2014-05-25 00:10:02.960418012+09:00 65.1 117 34 28.0 44.0 45.0
2014-05-25 00:11:03.211234875+09:00 66.3 120 34 28.0 44.0 45.0
2014-05-25 00:12:02.458205126+09:00 63.7 115 34 28.0 44.0 44.0
2014-05-25 00:13:02.715940424+09:00 65.3 120 34 28.0 44.0 46.0
2014-05-25 00:14:02.945108237+09:00 66.9 120 34 28.0 44.0 46.0
2014-05-25 00:15:03.180283106+09:00 65.6 120 34 28.0 43.0 45.0
2014-05-25 00:16:03.946422282+09:00 65.7 120 34 28.0 44.0 46.0
2014-05-25 00:17:03.851754226+09:00 64.4 0 34 28.0 44.0 45.0
2014-05-25 00:18:04.128084906+09:00 65.5 0 34 28.0 43.0 45.0
2014-05-25 00:19:04.019619909+09:00 65.9 0 34 28.0 42.0 46.0
2014-05-25 00:20:02.984672447+09:00 65.3 0 34 28.0 44.0 45.0
2014-05-25 00:21:04.326406869+09:00 65.9 0 34 28.0 44.0 45.0
F-PLUG
F-PLUG
~/bin/logsensor.shでは、電力、室温、コア温度の最低、平均、最高を出力する事にした。但し、これまでの記録されたコア温度のみの行もあるので、フィールド数"NF"が6より大きい場合にのみ電力~室温を拾うようにケア。
#!/bin/bash

awk '
BEGIN {
watt_min=999;watt_max=0;watt_sum=0;watt_cnt=0;
temp_min=999;temp_max=0;temp_sum=0;temp_cnt=0;
core_min=999;core_max=0;core_sum=0;core_cnt=0;
}
{
if ( 6 < NF ){
i = 3; // Watt
if($i < watt_min){watt_min=$i};
if(watt_max < $i){watt_max=$i};
watt_sum += $i;
watt_cnt++;

i = 4; // Illuminance
i = 5; // Humidity
i = 6; // Temperature
if($i < temp_min){temp_min=$i};
if(temp_max < $i){temp_max=$i};
temp_sum += $i;
temp_cnt++;

i = 7;
} else
i = 3;
for (; i <= NF; i++ ){
if($i < core_min){core_min=$i};
if(core_max < $i){core_max=$i};
core_sum += $i;
core_cnt++;
}

date=$1;
if(!length(start)){start=date;}
}
END {
printf "%s, %s, %.1f, %.1f, %.1f, ", start, date, watt_min, watt_sum/watt_cnt, watt_max;
printf "%.1f, %.1f, %.1f, ", temp_min, temp_sum/temp_cnt, temp_max;
printf "%.1f, %.1f, %.1f\n", core_min, core_sum/core_cnt, core_max;
}
' $*