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>
This commit is contained in:
Gérondal Thibault
2020-07-03 23:21:12 +02:00
committed by Paul Spooren
parent f4e878c215
commit e2b3fec6bf
2 changed files with 28 additions and 1 deletions
@@ -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 }