What am I doing wrong here? I see an error in my messages files of prometheus complaining about duplicate entries. See last 3 lines of wget.
On OpenWRT I see multipule devices/sensors with the same entry: /usr/lib/lua/prometheus-collectors/hwmon.lua. Anyone good with lua who can help me? How can I figure out who the maintainer is?
Machine: ASUS ZenWiFi BT8
Release: custom 25.12 build as of yesterday
root# wget -q -O- http://openwrt:9100/metrics | grep node_hwmon_temp_celsius
# TYPE node_hwmon_temp_celsius gauge
node_hwmon_temp_celsius{sensor="temp1",chip="thermal_thermal_zone0"} 52.545
node_hwmon_temp_celsius{sensor="temp1",chip="mdio-bus_mdio-bus:05"} 46.38
node_hwmon_temp_celsius{sensor="temp1",chip="ieee80211_phy0"} 57
node_hwmon_temp_celsius{sensor="temp1",chip="ieee80211_phy0"} 51
node_hwmon_temp_celsius{sensor="temp1",chip="ieee80211_phy0"} 51
/usr/lib/lua/prometheus-collectors/hwmon.lua
-- Produce node_hwmon_temp_celsius
for sensor_path in fs.glob(hwmon_path .. "/temp*_input") do
local sensor = string.gsub(fs.basename(sensor_path), "_input$", "")
local temp = get_contents(sensor_path) / 1000
metric_temp_celsius({chip=chip, sensor=sensor}, temp)
end
root# ls /sys/class/hwmon/hwmon*/temp*_input
/sys/class/hwmon/hwmon0/temp1_input /sys/class/hwmon/hwmon3/temp1_input
/sys/class/hwmon/hwmon1/temp1_input /sys/class/hwmon/hwmon4/temp1_input
/sys/class/hwmon/hwmon2/temp1_input
root# cat /sys/class/hwmon/hwmon*/temp*_input
52695
46574
57000
51000
53000
It's because lua code is looking at the "device" file that shows one phy but there are 3 radios (2.4, 5, 6Ghz)
Maybe the logic needs to be updated?
root# ls -ltra /sys/class/hwmon/hwmon?/device
lrwxrwxrwx 1 root root 0 Mar 7 06:50 /sys/class/hwmon/hwmon4/device -> ../../phy0
lrwxrwxrwx 1 root root 0 Mar 7 06:50 /sys/class/hwmon/hwmon3/device -> ../../phy0
lrwxrwxrwx 1 root root 0 Mar 7 06:50 /sys/class/hwmon/hwmon2/device -> ../../phy0
lrwxrwxrwx 1 root root 0 Mar 7 06:50 /sys/class/hwmon/hwmon1/device -> ../../../mdio-bus:05
lrwxrwxrwx 1 root root 0 Mar 7 06:50 /sys/class/hwmon/hwmon0/device -> ../../thermal_zone0
Maybe use the contents of /sys/class/hwmon/hwmon?/name instead? line 25 of hwmon.lua. I'm not sure how to change that in lua to test. 
-- See https://github.com/prometheus/node_exporter/blob/7c564bcbeffade3dacac43b07c2eeca4957ca71d/collector/hwmon_linux.go#L355
local chip = chip_name
local real_dev_path, status = fs.realpath(hwmon_path .. "/device")
if not status then
local dev_name = fs.basename(real_dev_path)
local dev_type = fs.basename(fs.dirname(real_dev_path))
chip = dev_type .. "_" .. dev_name
end
root# cat /sys/class/hwmon/hwmon?/name
cpu_thermal
mdio_bus:05
mt7996_phy0.0
mt7996_phy0.1
mt7996_phy0.2
Changing line 42, seems to make things more unique: metric_temp_celsius({chip=chip_name, sensor=sensor}, temp)
root# wget -q -O- http://openwrt:9100/metrics | grep hwmon_temp_celsi
# TYPE node_hwmon_temp_celsius gauge
node_hwmon_temp_celsius{sensor="temp1",chip="cpu_thermal"} 51.521
node_hwmon_temp_celsius{sensor="temp1",chip="mdio_bus:05"} 45.214
node_hwmon_temp_celsius{sensor="temp1",chip="mt7996_phy0.0"} 55
node_hwmon_temp_celsius{sensor="temp1",chip="mt7996_phy0.1"} 50
node_hwmon_temp_celsius{sensor="temp1",chip="mt7996_phy0.2"} 51
Testing to see if this works, after a custom build. Need to figure out how/where I can set this after doing a compile or first boot.
sed -i 's/\(metric_temp_celsius({chip=chip\)/\1_name/' /usr/lib/lua/prometheus-collectors/hwmon.lua