From: Joel Pettersson Date: Sat, 13 May 2023 10:26:45 +0000 (+0200) Subject: prometheus-node-exporter-lua: Add thermal collector X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=7b683fd6577c6812c7e9ca05b98ff8ed7d63b574;p=feed%2Fpackages.git prometheus-node-exporter-lua: Add thermal collector Signed-off-by: Joel Pettersson (cherry picked from commit 1eeb1dc2de82c093e2cd1ccc71ffd36a449301f9) --- diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index a69f5320d6..3ac56eefac 100644 --- a/utils/prometheus-node-exporter-lua/Makefile +++ b/utils/prometheus-node-exporter-lua/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=prometheus-node-exporter-lua -PKG_VERSION:=2022.08.08 +PKG_VERSION:=2023.05.14 PKG_RELEASE:=1 PKG_MAINTAINER:=Etienne CHAMPETIER @@ -158,6 +158,17 @@ define Package/prometheus-node-exporter-lua-textfile/install $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/textfile.lua $(1)/usr/lib/lua/prometheus-collectors/ endef +define Package/prometheus-node-exporter-lua-thermal + $(call Package/prometheus-node-exporter-lua/Default) + TITLE+= (thermal collector) + DEPENDS:=prometheus-node-exporter-lua +endef + +define Package/prometheus-node-exporter-lua-thermal/install + $(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors + $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/thermal.lua $(1)/usr/lib/lua/prometheus-collectors/ +endef + define Package/prometheus-node-exporter-lua-ubnt-manager $(call Package/prometheus-node-exporter-lua/Default) TITLE+= (ubnt-manager collector) @@ -234,6 +245,7 @@ $(eval $(call BuildPackage,prometheus-node-exporter-lua-nat_traffic)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-netstat)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-openwrt)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-textfile)) +$(eval $(call BuildPackage,prometheus-node-exporter-lua-thermal)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-ubnt-manager)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-uci_dhcp_host)) $(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi)) diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/thermal.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/thermal.lua new file mode 100644 index 0000000000..3996ea581b --- /dev/null +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/thermal.lua @@ -0,0 +1,46 @@ +-- thermal collector +local function scrape() + local i = 0 + local temp_metric = metric("node_thermal_zone_temp", "gauge") + + while true do + local zonePath = "/sys/class/thermal/thermal_zone" .. i + + -- required attributes + + local typ = string.match(get_contents(zonePath .. "/type"), "^%s*(.-)%s*$") + if not typ then + break + end + + local policy = string.match(get_contents(zonePath .. "/policy"), "^%s*(.-)%s*$") + if not policy then + break + end + + local temp = string.match(get_contents(zonePath .. "/temp"), "(%d+)") + if not temp then + break + end + + local labels = {zone = i, type = typ, policy = policy} + + -- optional attributes + + local mode = string.match(get_contents(zonePath .. "/mode"), "^%s*(.-)%s*$") + if mode then + labels.mode = mode + end + + local passive = string.match(get_contents(zonePath .. "/passive"), "(%d+)") + if passive then + labels.passive = passive + end + + temp_metric(labels, temp / 1000) + + i = i + 1 + end +end + +return { scrape = scrape }