prometheus-node-exporter-lua: fix hostapd stations
We can only utilize statistics from interfaces having ubus interface. Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
parent
5a782988bd
commit
245d63426b
2 changed files with 60 additions and 34 deletions
|
@ -4,7 +4,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=prometheus-node-exporter-lua
|
PKG_NAME:=prometheus-node-exporter-lua
|
||||||
PKG_VERSION:=2022.06.29
|
PKG_VERSION:=2022.08.07
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com>
|
PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com>
|
||||||
|
|
|
@ -1,52 +1,78 @@
|
||||||
local ubus = require "ubus"
|
local ubus = require "ubus"
|
||||||
local bit32 = require "bit32"
|
local bit32 = require "bit32"
|
||||||
|
|
||||||
|
local function get_wifi_interfaces()
|
||||||
|
local conn = ubus.connect()
|
||||||
|
local ubuslist = conn:objects()
|
||||||
|
local interfaces = {}
|
||||||
|
|
||||||
|
for _,net in ipairs(ubuslist) do
|
||||||
|
if net.find(net,"hostapd.") then
|
||||||
|
local ifname = net:gsub("hostapd.", "")
|
||||||
|
table.insert(interfaces, ifname);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
conn:close()
|
||||||
|
return interfaces;
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_ubus_interface(ubus_interfaces, interface)
|
||||||
|
for i=1,#ubus_interfaces do
|
||||||
|
if ubus_interfaces[i] == interface then return true end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local function get_wifi_interface_labels()
|
local function get_wifi_interface_labels()
|
||||||
local u = ubus.connect()
|
local u = ubus.connect()
|
||||||
local status = u:call("network.wireless", "status", {})
|
local status = u:call("network.wireless", "status", {})
|
||||||
local interfaces = {}
|
local interfaces = {}
|
||||||
|
local ubus_interfaces = get_wifi_interfaces()
|
||||||
|
|
||||||
for _, dev_table in pairs(status) do
|
for _, dev_table in pairs(status) do
|
||||||
for _, intf in ipairs(dev_table['interfaces']) do
|
for _, intf in ipairs(dev_table['interfaces']) do
|
||||||
local cfg = intf['config']
|
local cfg = intf['config']
|
||||||
|
|
||||||
-- Migrate this to ubus interface once it exposes all interesting labels
|
if is_ubus_interface(ubus_interfaces, cfg['ifname']) then
|
||||||
local handle = io.popen("hostapd_cli -i " .. cfg['ifname'] .." status")
|
|
||||||
local hostapd_status = handle:read("*a")
|
|
||||||
handle:close()
|
|
||||||
|
|
||||||
local hostapd = {}
|
-- Migrate this to ubus interface once it exposes all interesting labels
|
||||||
local bss_idx = -1
|
local handle = io.popen("hostapd_cli -i " .. cfg['ifname'] .." status")
|
||||||
for line in hostapd_status:gmatch("[^\r\n]+") do
|
local hostapd_status = handle:read("*a")
|
||||||
local name, value = string.match(line, "(.+)=(.+)")
|
handle:close()
|
||||||
if name == "freq" then
|
|
||||||
hostapd["freq"] = value
|
local hostapd = {}
|
||||||
elseif name == "channel" then
|
local bss_idx = -1
|
||||||
hostapd["channel"] = value
|
for line in hostapd_status:gmatch("[^\r\n]+") do
|
||||||
-- hostapd gives us all bss on the relevant phy, find the one we're interested in
|
local name, value = string.match(line, "(.+)=(.+)")
|
||||||
elseif string.match(name, "bss%[%d%]") then
|
if name == "freq" then
|
||||||
if value == cfg['ifname'] then
|
hostapd["freq"] = value
|
||||||
bss_idx = tonumber(string.match(name, "bss%[(%d)%]"))
|
elseif name == "channel" then
|
||||||
end
|
hostapd["channel"] = value
|
||||||
elseif bss_idx >= 0 then
|
-- hostapd gives us all bss on the relevant phy, find the one we're interested in
|
||||||
if name == "bssid[" .. bss_idx .. "]" then
|
elseif string.match(name, "bss%[%d%]") then
|
||||||
hostapd["bssid"] = value
|
if value == cfg['ifname'] then
|
||||||
elseif name == "ssid[" .. bss_idx .. "]" then
|
bss_idx = tonumber(string.match(name, "bss%[(%d)%]"))
|
||||||
hostapd["ssid"] = value
|
end
|
||||||
|
elseif bss_idx >= 0 then
|
||||||
|
if name == "bssid[" .. bss_idx .. "]" then
|
||||||
|
hostapd["bssid"] = value
|
||||||
|
elseif name == "ssid[" .. bss_idx .. "]" then
|
||||||
|
hostapd["ssid"] = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local labels = {
|
||||||
|
vif = cfg['ifname'],
|
||||||
|
ssid = hostapd['ssid'],
|
||||||
|
bssid = hostapd['bssid'],
|
||||||
|
encryption = cfg['encryption'], -- In a mixed scenario it would be good to know if A or B was used
|
||||||
|
frequency = hostapd['freq'],
|
||||||
|
channel = hostapd['channel'],
|
||||||
|
}
|
||||||
|
|
||||||
|
table.insert(interfaces, labels)
|
||||||
end
|
end
|
||||||
|
|
||||||
local labels = {
|
|
||||||
vif = cfg['ifname'],
|
|
||||||
ssid = hostapd['ssid'],
|
|
||||||
bssid = hostapd['bssid'],
|
|
||||||
encryption = cfg['encryption'], -- In a mixed scenario it would be good to know if A or B was used
|
|
||||||
frequency = hostapd['freq'],
|
|
||||||
channel = hostapd['channel'],
|
|
||||||
}
|
|
||||||
|
|
||||||
table.insert(interfaces, labels)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue