From e2b3fec6bfca8e9843aa5ec297803869061d2a5d Mon Sep 17 00:00:00 2001 From: Gérondal Thibault Date: Fri, 3 Jul 2020 23:21:12 +0200 Subject: prometheus-node-exporter-lua: uci_dhcp_host module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua (limited to 'utils/prometheus-node-exporter-lua/files/usr/lib/lua') diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua new file mode 100644 index 000000000..950962599 --- /dev/null +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/uci_dhcp_host.lua @@ -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 } -- cgit v1.2.3