aboutsummaryrefslogtreecommitdiff
path: root/utils/prometheus-node-exporter-lua/files/usr/lib/lua
diff options
context:
space:
mode:
authorMartin Weinelt <hexa@darmstadt.ccc.de>2021-06-26 02:15:17 +0200
committerEtienne Champetier <champetier.etienne@gmail.com>2021-07-06 13:37:36 -0400
commita1b145abb026938ca5e2c205396cc007b49da15f (patch)
tree88559df7bcb986bcb219b887b6528ed181cf0595 /utils/prometheus-node-exporter-lua/files/usr/lib/lua
parenta98596168ade0ace524ca51067f00e2956ec8cee (diff)
prometheus-node-exporter-lua: fix corner case in hostapd_stations
There was a corner case, when a vif had no stations, that evaluate_metrics for a station that was nil and had no collected metrics would have been called. Comment the code, to make it easier to understand and follow, and simplify some variable names along the way. Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
Diffstat (limited to 'utils/prometheus-node-exporter-lua/files/usr/lib/lua')
-rw-r--r--utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hostapd_stations.lua31
1 files changed, 19 insertions, 12 deletions
diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hostapd_stations.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hostapd_stations.lua
index 9f7f6e4ad..a3e6c331a 100644
--- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hostapd_stations.lua
+++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hostapd_stations.lua
@@ -139,26 +139,33 @@ local function scrape()
local all_sta = handle:read("*a")
handle:close()
- local current_station = nil
- local current_station_values = {}
+ local station = nil
+ local metrics = {}
for line in all_sta:gmatch("[^\r\n]+") do
if string.match(line, "^%x[0123456789aAbBcCdDeE]:%x%x:%x%x:%x%x:%x%x:%x%x$") then
- if current_station ~= nil then
- labels.station = current_station
- evaluate_metrics(labels, current_station_values)
+ -- the first time we see a mac we have no previous station to eval, so don't
+ if station ~= nil then
+ labels.station = station
+ evaluate_metrics(labels, metrics)
end
- current_station = line
- current_station_values = {}
+
+ -- remember current station bssid and truncate metrics
+ station = line
+ metrics = {}
else
- local name, value = string.match(line, "(.+)=(.+)")
- if name ~= nil then
- current_station_values[name] = value
+ local key, value = string.match(line, "(.+)=(.+)")
+ if key ~= nil then
+ metrics[key] = value
end
end
end
- labels.station = current_station
- evaluate_metrics(labels, current_station_values)
+
+ -- the final station, check if there ever was one, will need a metrics eval as well
+ if station ~= nil then
+ labels.station = station
+ evaluate_metrics(labels, metrics)
+ end
end
end