From 6a4d53f4f467c57aeb0d9a32d1d84e01fcfdeabd Mon Sep 17 00:00:00 2001 From: Alban Bedel Date: Sat, 12 Nov 2022 15:01:11 +0100 Subject: [PATCH 1/2] prometheus-node-exporter-lua: wifi: Follow prometheus best practices The wifi exporter currently put all the config as labels in each series. This is not a recommended practice because any change in the wifi configuration will create a new set of time series. Metrics should use a minial set of label to be unique, further metadata should be put into a dedicated metric with a constant value of 1. This patch add 2 new metrics `wifi_radio_config` and `wifi_network_config` to carry the configuration related labels. The `metric_wifi_network_*` metrics now only include the interface name and radio divice labels. Althought the interface name is unique the radio label is still provided to allow easy correlation with radio level metrics. The label matching the radio device is also renamed from `device` to `radio` to make things a bit clearer. Beside all these changes most visualisation setup should continue to work without changes as the core matching label `ifname` stays the same. Now that we report the radio level stuff separately also add a new metric for the radio's channel. Signed-off-by: Alban Bedel --- .../lib/lua/prometheus-collectors/wifi.lua | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua index 4b1e8f4020..00cf4c883f 100644 --- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua @@ -2,6 +2,9 @@ local ubus = require "ubus" local iwinfo = require "iwinfo" local function scrape() + local metric_wifi_radio_config = metric("wifi_radio_config","gauge") + local metric_wifi_radio_channel = metric("wifi_radio_channel","gauge") + local metric_wifi_network_config = metric("wifi_network_config","gauge") local metric_wifi_network_quality = metric("wifi_network_quality","gauge") local metric_wifi_network_bitrate = metric("wifi_network_bitrate","gauge") local metric_wifi_network_noise = metric("wifi_network_noise_dbm","gauge") @@ -11,19 +14,33 @@ local function scrape() local status = u:call("network.wireless", "status", {}) for dev, dev_table in pairs(status) do + local radio_config = dev_table['config'] + local radio_config_labels = { + radio = dev, + hwmode = radio_config['hwmode'], + channel = radio_config['channel'], + country = radio_config['country'], + } + local radio_labels = { + radio = dev, + } + metric_wifi_radio_config(radio_config_labels, 1) + metric_wifi_radio_channel(radio_labels, radio_config['channel']) + for _, intf in ipairs(dev_table['interfaces']) do local ifname = intf['ifname'] if ifname ~= nil then local iw = iwinfo[iwinfo.type(ifname)] - local labels = { - channel = iw.channel(ifname), + local network_config_labels = { ssid = iw.ssid(ifname), bssid = string.lower(iw.bssid(ifname)), mode = iw.mode(ifname), ifname = ifname, - country = iw.country(ifname), - frequency = iw.frequency(ifname), - device = dev, + radio = dev, + } + local network_labels = { + ifname = ifname, + radio = dev, } local qc = iw.quality(ifname) or 0 @@ -33,10 +50,11 @@ local function scrape() quality = math.floor((100 / qm) * qc) end - metric_wifi_network_quality(labels, quality) - metric_wifi_network_noise(labels, iw.noise(ifname) or 0) - metric_wifi_network_bitrate(labels, iw.bitrate(ifname) or 0) - metric_wifi_network_signal(labels, iw.signal(ifname) or -255) + metric_wifi_network_config(network_config_labels, 1) + metric_wifi_network_quality(network_labels, quality) + metric_wifi_network_noise(network_labels, iw.noise(ifname) or 0) + metric_wifi_network_bitrate(network_labels, iw.bitrate(ifname) or 0) + metric_wifi_network_signal(network_labels, iw.signal(ifname) or -255) end end end From bfeba48fac0a7c9eab288a84f3ed1f6b2d4c5ff0 Mon Sep 17 00:00:00 2001 From: Alban Bedel Date: Sat, 12 Nov 2022 15:27:06 +0100 Subject: [PATCH 2/2] prometheus-node-exporter-lua: wifi: Add a metric for the number of stations The number of stations is already provided by the wifi stations collector. But this collector also provides per station metrics which can create an unbonded number of time series in the prometheus database. Having such metrics can also be a privacy issues depending on who can access the monitoring data. But the number of connected stations is still an interesting metric, especially if you have many access points. This patch add the `wifi_network_stations_total` metric to the main wifi collector to fill this gap. Signed-off-by: Alban Bedel --- .../files/usr/lib/lua/prometheus-collectors/wifi.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua index 00cf4c883f..d00d97b31f 100644 --- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/wifi.lua @@ -9,6 +9,7 @@ local function scrape() local metric_wifi_network_bitrate = metric("wifi_network_bitrate","gauge") local metric_wifi_network_noise = metric("wifi_network_noise_dbm","gauge") local metric_wifi_network_signal = metric("wifi_network_signal_dbm","gauge") + local metric_wifi_network_stations_total = metric("wifi_network_stations_total","gauge") local u = ubus.connect() local status = u:call("network.wireless", "status", {}) @@ -50,11 +51,17 @@ local function scrape() quality = math.floor((100 / qm) * qc) end + local stations = 0 + for _ in pairs(iw.assoclist(ifname)) do + stations = stations + 1 + end + metric_wifi_network_config(network_config_labels, 1) metric_wifi_network_quality(network_labels, quality) metric_wifi_network_noise(network_labels, iw.noise(ifname) or 0) metric_wifi_network_bitrate(network_labels, iw.bitrate(ifname) or 0) metric_wifi_network_signal(network_labels, iw.signal(ifname) or -255) + metric_wifi_network_stations_total(network_labels, stations) end end end