1
0
mirror of https://git.openwrt.org/feed/packages.git synced 2024-06-14 03:13:54 +02:00

prometheus-node-exporter-lua: Add wifi_station_count

To return the number of connected clients.

At present this can be partially inferred by using a count() over one of
the existing metrics, however this doesn't handle the case when there
are no connected clients. When that happens, the count() will return no
data instead of 0.

Signed-off-by: Alex Tomlins <alex@tomlins.org.uk>
(cherry picked from commit 1237e196b4)
This commit is contained in:
Alex Tomlins 2019-04-07 14:01:12 +01:00 committed by Etienne Champetier
parent 0d224bdfa1
commit 1014b09871

View File

@ -2,6 +2,7 @@ local ubus = require "ubus"
local iwinfo = require "iwinfo"
local function scrape()
local metric_wifi_stations = metric("wifi_stations", "gauge")
local metric_wifi_station_signal = metric("wifi_station_signal_dbm","gauge")
local metric_wifi_station_tx_packets = metric("wifi_station_tx_packets_total","counter")
local metric_wifi_station_rx_packets = metric("wifi_station_rx_packets_total","counter")
@ -13,6 +14,7 @@ local function scrape()
for _, intf in ipairs(dev_table['interfaces']) do
local ifname = intf['ifname']
local iw = iwinfo[iwinfo.type(ifname)]
local count = 0
local assoclist = iw.assoclist(ifname)
for mac, station in pairs(assoclist) do
@ -23,7 +25,9 @@ local function scrape()
metric_wifi_station_signal(labels, station.signal)
metric_wifi_station_tx_packets(labels, station.tx_packets)
metric_wifi_station_rx_packets(labels, station.rx_packets)
count = count + 1
end
metric_wifi_stations({ifname = ifname}, count)
end
end
end