diff options
| author | Ivan Mironov <mironov.ivan@gmail.com> | 2023-07-13 01:45:44 +0200 |
|---|---|---|
| committer | Etienne Champetier <champetier.etienne@gmail.com> | 2023-10-15 11:13:17 -0400 |
| commit | 431fefbdea559625c5b46ff2011237fefcbf1c1c (patch) | |
| tree | 143d555ce3a0ef717c8088fa3f11c32a33b0dc15 /utils/prometheus-node-exporter-lua | |
| parent | 86df457120ab726cb9125de945522a0ecfafa9b1 (diff) | |
prometheus-node-exporter-lua: add basic hwmon exporter
This collector supports following metrics:
* node_hwmon_temp_celsius
* node_hwmon_pwm
and following auxiliary mappings:
* node_hwmon_chip_names
* node_hwmon_sensor_label
Tested on:
* Banana Pi BPI-r3 / OpenWrt 23.05.0-rc2
* TP-Link Archer C7 v5 / OpenWrt 22.03.5
Signed-off-by: Ivan Mironov <mironov.ivan@gmail.com>
Diffstat (limited to 'utils/prometheus-node-exporter-lua')
| -rw-r--r-- | utils/prometheus-node-exporter-lua/Makefile | 12 | ||||
| -rw-r--r-- | utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hwmon.lua | 58 |
2 files changed, 70 insertions, 0 deletions
diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index 3ac56eefa..c3b8bc723 100644 --- a/utils/prometheus-node-exporter-lua/Makefile +++ b/utils/prometheus-node-exporter-lua/Makefile @@ -103,6 +103,17 @@ define Package/prometheus-node-exporter-lua-hostapd_ubus_stations/install $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/hostapd_ubus_stations.lua $(1)/usr/lib/lua/prometheus-collectors/ endef +define Package/prometheus-node-exporter-lua-hwmon + $(call Package/prometheus-node-exporter-lua/Default) + TITLE+= (hwmon collector) + DEPENDS:=prometheus-node-exporter-lua +luci-lib-nixio +endef + +define Package/prometheus-node-exporter-lua-hwmon/install + $(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors + $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/hwmon.lua $(1)/usr/lib/lua/prometheus-collectors/ +endef + define Package/prometheus-node-exporter-lua-ltq-dsl $(call Package/prometheus-node-exporter-lua/Default) TITLE+= (lantiq dsl collector) @@ -240,6 +251,7 @@ $(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx7)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-dawn)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-hostapd_stations)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-hostapd_ubus_stations)) +$(eval $(call BuildPackage,prometheus-node-exporter-lua-hwmon)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-ltq-dsl)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-nat_traffic)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-netstat)) diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hwmon.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hwmon.lua new file mode 100644 index 000000000..3e00f0524 --- /dev/null +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hwmon.lua @@ -0,0 +1,58 @@ +#!/usr/bin/lua + +local fs = require "nixio.fs" + +local function rtrim(s) + return string.gsub(s, "\n$", "") +end + +local function scrape() + local metric_chip_names = metric("node_hwmon_chip_names", "gauge") + local metric_sensor_label = metric("node_hwmon_sensor_label", "gauge") + local metric_temp_celsius = metric("node_hwmon_temp_celsius", "gauge") + local metric_pwm = metric("node_hwmon_pwm", "gauge") + + for hwmon_path in fs.glob("/sys/class/hwmon/hwmon*") do + -- Produce node_hwmon_chip_names + -- See https://github.com/prometheus/node_exporter/blob/7c564bcbeffade3dacac43b07c2eeca4957ca71d/collector/hwmon_linux.go#L415 + local chip_name = rtrim(get_contents(hwmon_path .. "/name")) + if chip_name == "" then + chip_name = fs.basename(hwmon_path) + end + + -- 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 + metric_chip_names({chip=chip, chip_name=chip_name}, 1) + + -- Produce node_hwmon_sensor_label + for sensor_path in fs.glob(hwmon_path .. "/*_label") do + local sensor = string.gsub(fs.basename(sensor_path), "_label$", "") + local sensor_label = rtrim(get_contents(sensor_path)) + metric_sensor_label({chip=chip, sensor=sensor, label=sensor_label}, 1) + end + + -- 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 + + -- Produce node_hwmon_pwm + for sensor_path in fs.glob(hwmon_path .. "/pwm*") do + local sensor = fs.basename(sensor_path) + if string.match(sensor, "^pwm[0-9]+$") then + local pwm = rtrim(get_contents(sensor_path)) + metric_pwm({chip=chip, sensor=sensor}, pwm) + end + end + end +end + +return { scrape = scrape } |
