1、查看信息来源
#查看来源
cat /sys/class/thermal/thermal_zone0/type
#查看值
cat /sys/class/thermal/thermal_zone0/temp
2、编辑脚本
sudo vim /opt/snmp_extend.sh
#!/bin/bash
declare -A SENSOR_MAP
SENSOR_MAP[A0]="0"
SENSOR_MAP[CPU]="1"
SENSOR_MAP[GPU]="2"
SENSOR_MAP[PLL]="3"
SENSOR_MAP[PMIC]="4"
SENSOR_MAP[Thermal]="5"
function PrintUsage() {
echo "Usage: snmp_extend.sh SENSOR -g OID"
}
if [[ "$2" = "-g" ]]; then
ZONE=${SENSOR_MAP[$1]}
if [[ $ZONE ]]; then
SENSOR_NAME=$(cat /sys/class/thermal/thermal_zone$ZONE/type)
SENSOR_TEMP=$(cat /sys/class/thermal/thermal_zone$ZONE/temp)
echo $3
echo integer
echo $SENSOR_TEMP
fi
elif [[ "$2" = "-n" ]]; then
exit 0
else
PrintUsage
fi
3、添加到 /etc/snmp/snmpd.conf中
sudo vim /etc/snmp/snmpd.conf
#增加oid
view systemonly included .1.3.6.1.4.1.1989
#pass 动态增加节点
pass .1.3.6.1.4.1.1989.10.1 /opt/snmp_extend.sh A0
pass .1.3.6.1.4.1.1989.10.2 /opt/snmp_extend.sh CPU
pass .1.3.6.1.4.1.1989.10.3 /opt/snmp_extend.sh GPU
pass .1.3.6.1.4.1.1989.10.4 /opt/snmp_extend.sh PLL
pass .1.3.6.1.4.1.1989.10.5 /opt/snmp_extend.sh PMIC
pass .1.3.6.1.4.1.1989.10.6 /opt/snmp_extend.sh Thermal
4、重启snmp服务器并查看
$ systemctl restart snmpd
$ snmpget -v2c -c public 127.0.0.1 .1.3.6.1.4.1.1989.10.1
iso.3.6.1.4.1.1989.10.1 = INTEGER: 39500