Skip to content

Instantly share code, notes, and snippets.

@TETYYS
Last active August 16, 2024 18:19
Show Gist options
  • Save TETYYS/b2d2636921143f99bf2412cd9cae43ff to your computer and use it in GitHub Desktop.
Save TETYYS/b2d2636921143f99bf2412cd9cae43ff to your computer and use it in GitHub Desktop.
Translates hwmon disk temp chip id to device model. Use with max(node_hwmon_temp_celsius{chip=~"^target(.+)"}) by (chip) * on(chip) group_left(model) (node_hwmon_chip_info)
#!/bin/bash
metrics() {
echo "# HELP node_hwmon_chip_info chip to model name mapping"
echo "# TYPE node_hwmon_chip_info gauge"
for file in /sys/class/hwmon/*; do
symlink_target="$(readlink $file)"
if [[ "$symlink_target" != *"/target"* ]]; then
continue
fi
chip="$(echo "$symlink_target" | sed -E 's/^.+target(.+)\/hwmon\/hwmon[[:digit:]]+/target\1/' | sed 's/\//_/')"
block=($file/device/block/*)
model="$(udevadm info --query=property --path="$block" | grep -m 1 ID_SERIAL | sed 's/ID_SERIAL=//')"
echo "node_hwmon_chip_info{chip="'"'$chip'"'",model="'"'$model'"'"} 1.0"
done
}
metrics > /var/lib/prometheus/node-exporter/chip_info.prom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment