Browse Source

prometheus-node-exporter-lua: uci_dhcp_host module

Extract data from configuration file /etc/config/dhcp and create labels
{name, ip, mac, dns} via uci. Those labels are useful in order to craft
complex prometheus queries as replacing the MAC address to a custom
name.  E.g.: wifi_station_signal_dbm * on (mac) group_left(name)
uci_dhcp_host or on (mac) label_replace(wifi_station_signal_dbm, "name",
"$1", "mac", "(.+)")

Signed-off-by: Gérondal Thibault <contact@tycale.be>
lilik-openwrt-22.03
Gérondal Thibault 5 years ago
committed by Paul Spooren
parent
commit
e2b3fec6bf
2 changed files with 28 additions and 1 deletions
  1. +13
    -1
      utils/prometheus-node-exporter-lua/Makefile
  2. +15
    -0
      utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua

+ 13
- 1
utils/prometheus-node-exporter-lua/Makefile View File

@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=prometheus-node-exporter-lua
PKG_VERSION:=2020.06.26
PKG_VERSION:=2020.07.04
PKG_RELEASE:=1
PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com>
@ -40,6 +40,12 @@ define Package/prometheus-node-exporter-lua-nat_traffic
DEPENDS:=prometheus-node-exporter-lua
endef
define Package/prometheus-node-exporter-lua-uci_dhcp_host
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (uci_dhcp_host collector)
DEPENDS:=prometheus-node-exporter-lua +libuci-lua
endef
define Package/prometheus-node-exporter-lua-netstat
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (netstat collector)
@ -119,6 +125,11 @@ define Package/prometheus-node-exporter-lua-nat_traffic/install
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/nat_traffic.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
define Package/prometheus-node-exporter-lua-uci_dhcp_host/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua $(1)/usr/lib/lua/prometheus-collectors/
endef
define Package/prometheus-node-exporter-lua-netstat/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/netstat.lua $(1)/usr/lib/lua/prometheus-collectors/
@ -167,6 +178,7 @@ endef
$(eval $(call BuildPackage,prometheus-node-exporter-lua))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-nat_traffic))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-netstat))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-uci_dhcp_host))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-wifi_stations))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-hostapd_stations))


+ 15
- 0
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua View File

@ -0,0 +1,15 @@
local uci=require("uci")
local function scrape()
local curs=uci.cursor()
local metric_uci_host = metric("uci_dhcp_host", "gauge")
curs:foreach("dhcp", "host", function(s)
if s[".type"] == "host" then
labels = {name=s["name"], mac=string.upper(s["mac"]), dns=s["dns"], ip=s["ip"]}
metric_uci_host(labels, 1)
end
end)
end
return { scrape = scrape }

Loading…
Cancel
Save