prometheus-node-exporter-lua: rewrite wifi scraper
On my bullet m2, scrape duration goes from between 0.2 and 0.5 to a stable 0.025 We also don't depend on luci anymore This remove wifi_network_up metric, but this metric was buggy wifi_network_up{ifname="wlan0-1",ssid="test1",channel="11",mode="Master",bssid="12:34:56:78:9A:BC",country="FR",frequency="2.462"} 1 wifi_network_up{ifname="radio0.network2",ssid="test1",channel="11",mode="Master",country="US",frequency="2.462"} 0 Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
This commit is contained in:
parent
747f4ce7af
commit
7b1b69ca6c
2 changed files with 39 additions and 46 deletions
|
@ -16,7 +16,7 @@ define Package/prometheus-node-exporter-lua
|
||||||
SECTION:=utils
|
SECTION:=utils
|
||||||
CATEGORY:=Utilities
|
CATEGORY:=Utilities
|
||||||
TITLE:=Provides system statistics as Prometheus scraping endpoint
|
TITLE:=Provides system statistics as Prometheus scraping endpoint
|
||||||
DEPENDS:=+luasocket
|
DEPENDS:=+luasocket +libiwinfo-lua +libubus-lua +lua
|
||||||
URL:=https://github.com/rbo/openwrt_exporter
|
URL:=https://github.com/rbo/openwrt_exporter
|
||||||
PKGARCH:=all
|
PKGARCH:=all
|
||||||
endef
|
endef
|
||||||
|
|
|
@ -69,11 +69,10 @@ function metric(name, mtype, labels, value)
|
||||||
return outputter
|
return outputter
|
||||||
end
|
end
|
||||||
|
|
||||||
function scraper_wifi()
|
local ubus = require "ubus"
|
||||||
local rv = { }
|
local iwinfo = require "iwinfo"
|
||||||
local ntm = require "luci.model.network".init()
|
|
||||||
|
|
||||||
local metric_wifi_network_up = metric("wifi_network_up","gauge")
|
function scraper_wifi()
|
||||||
local metric_wifi_network_quality = metric("wifi_network_quality","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_bitrate = metric("wifi_network_bitrate","gauge")
|
||||||
local metric_wifi_network_noise = metric("wifi_network_noise","gauge")
|
local metric_wifi_network_noise = metric("wifi_network_noise","gauge")
|
||||||
|
@ -83,53 +82,47 @@ function scraper_wifi()
|
||||||
local metric_wifi_station_tx_packets = metric("wifi_station_tx_packets","gauge")
|
local metric_wifi_station_tx_packets = metric("wifi_station_tx_packets","gauge")
|
||||||
local metric_wifi_station_rx_packets = metric("wifi_station_rx_packets","gauge")
|
local metric_wifi_station_rx_packets = metric("wifi_station_rx_packets","gauge")
|
||||||
|
|
||||||
local dev
|
local u = ubus.connect()
|
||||||
for _, dev in ipairs(ntm:get_wifidevs()) do
|
local status = u:call("network.wireless", "status", {})
|
||||||
local rd = {
|
|
||||||
up = dev:is_up(),
|
|
||||||
device = dev:name(),
|
|
||||||
name = dev:get_i18n(),
|
|
||||||
networks = { }
|
|
||||||
}
|
|
||||||
|
|
||||||
local net
|
for dev, dev_table in pairs(status) do
|
||||||
for _, net in ipairs(dev:get_wifinets()) do
|
for _, intf in ipairs(dev_table['interfaces']) do
|
||||||
|
local ifname = intf['ifname']
|
||||||
|
local iw = iwinfo[iwinfo.type(ifname)]
|
||||||
local labels = {
|
local labels = {
|
||||||
channel = net:channel(),
|
channel = iw.channel(ifname),
|
||||||
ssid = net:active_ssid(),
|
ssid = iw.ssid(ifname),
|
||||||
bssid = net:active_bssid(),
|
bssid = iw.bssid(ifname),
|
||||||
mode = net:active_mode(),
|
mode = iw.mode(ifname),
|
||||||
ifname = net:ifname(),
|
ifname = ifname,
|
||||||
country = net:country(),
|
country = iw.country(ifname),
|
||||||
frequency = net:frequency(),
|
frequency = iw.frequency(ifname),
|
||||||
|
device = dev,
|
||||||
}
|
}
|
||||||
if net:is_up() then
|
|
||||||
metric_wifi_network_up(labels, 1)
|
|
||||||
local signal = net:signal_percent()
|
|
||||||
if signal ~= 0 then
|
|
||||||
metric_wifi_network_quality(labels, net:signal_percent())
|
|
||||||
end
|
|
||||||
metric_wifi_network_noise(labels, net:noise())
|
|
||||||
local bitrate = net:bitrate()
|
|
||||||
if bitrate then
|
|
||||||
metric_wifi_network_bitrate(labels, bitrate)
|
|
||||||
end
|
|
||||||
|
|
||||||
local assoclist = net:assoclist()
|
local qc = iw.quality(ifname) or 0
|
||||||
for mac, station in pairs(assoclist) do
|
local qm = iw.quality_max(ifname) or 0
|
||||||
local labels = {
|
local quality = 0
|
||||||
ifname = net:ifname(),
|
if qc > 0 and qm > 0 then
|
||||||
mac = mac,
|
quality = math.floor((100 / qm) * qc)
|
||||||
}
|
end
|
||||||
metric_wifi_station_signal(labels, station.signal)
|
|
||||||
metric_wifi_station_tx_packets(labels, station.tx_packets)
|
metric_wifi_network_quality(labels, quality)
|
||||||
metric_wifi_station_rx_packets(labels, station.rx_packets)
|
metric_wifi_network_noise(labels, iw.noise(ifname) or 0)
|
||||||
end
|
metric_wifi_network_bitrate(labels, iw.bitrate(ifname) or 0)
|
||||||
else
|
metric_wifi_network_signal(labels, iw.signal(ifname) or -255)
|
||||||
metric_wifi_network_up(labels, 0)
|
|
||||||
|
local assoclist = iw.assoclist(ifname)
|
||||||
|
for mac, station in pairs(assoclist) do
|
||||||
|
local labels = {
|
||||||
|
ifname = ifname,
|
||||||
|
mac = mac,
|
||||||
|
}
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rv[#rv+1] = rd
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue