綠由
原本在 github 就有好用的 awk script ipmitool
但不管 FreeBSD, Linux 都要再另外裝 gawk 才能正常運作, 所以就決定寫一個以 bourne shell script 弄一個萬用版本
作法
- 利用 read line 的方式, 一行一行處理 ipmitool sensor 輸出資料
- 取出幾個分類: degreesC, RPM, Volts, discrete
- 組合成 node-exporter 格式
結果
#!/bin/sh
CHECKTITLE=''
while read -r line
do
line=`echo line | sed 's;|;,;g'`
if [ -n "`echoline | awk -F, '{print 2}' | grep na`" ]; then
continue
fi
TMPTITLE=`echoline | awk -F, '{print 3}' | sed 's; ;;g'`
case "TMPTITLE" in
degreesC)
node='node_ipmi_temperature_celsius'
TITLE1="# HELP node Temperature sensor reading from ipmitool"
TITLE2="# TYPEnode gauge"
;;
RPM)
node='node_ipmi_speed_rpm'
TITLE1="# HELP node Fan sensor reading from ipmitool"
TITLE2="# TYPEnode gauge"
;;
Volts)
node='node_ipmi_volts'
TITLE1="# HELP node Voltage sensor reading from ipmitool"
TITLE2="# TYPEnode gauge"
;;
discrete)
node='node_ipmi_status'
TITLE1="# HELP node Chassis status sensor reading from ipmitool"
TITLE2="# TYPEnode gauge"
esac
if [ "CHECKTITLE" != "TMPTITLE" ]; then
echo TITLE1
echoTITLE2
CHECKTITLE=TMPTITLE
fi
FIELD1=`echoline | awk -F, '{print 1}' | tr [:upper:] [:lower:]`
FIELD2=`echoline | awk -F, '{print 2}'`
FIELD2=`printf "%f"FIELD2`
node="node"'{sensor="'FIELD1'"} 'FIELD2
echonode
done
過年弄了一個 bourne shell script 可產出 IPMI sensor node-exporter text prom 版本