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
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=Provides system statistics as Prometheus scraping endpoint
|
||||
DEPENDS:=+luasocket
|
||||
DEPENDS:=+luasocket +libiwinfo-lua +libubus-lua +lua
|
||||
URL:=https://github.com/rbo/openwrt_exporter
|
||||
PKGARCH:=all
|
||||
endef
|
||||
|
|
|
@ -69,11 +69,10 @@ function metric(name, mtype, labels, value)
|
|||
return outputter
|
||||
end
|
||||
|
||||
function scraper_wifi()
|
||||
local rv = { }
|
||||
local ntm = require "luci.model.network".init()
|
||||
local ubus = require "ubus"
|
||||
local iwinfo = require "iwinfo"
|
||||
|
||||
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_bitrate = metric("wifi_network_bitrate","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_rx_packets = metric("wifi_station_rx_packets","gauge")
|
||||
|
||||
local dev
|
||||
for _, dev in ipairs(ntm:get_wifidevs()) do
|
||||
local rd = {
|
||||
up = dev:is_up(),
|
||||
device = dev:name(),
|
||||
name = dev:get_i18n(),
|
||||
networks = { }
|
||||
}
|
||||
local u = ubus.connect()
|
||||
local status = u:call("network.wireless", "status", {})
|
||||
|
||||
local net
|
||||
for _, net in ipairs(dev:get_wifinets()) do
|
||||
for dev, dev_table in pairs(status) do
|
||||
for _, intf in ipairs(dev_table['interfaces']) do
|
||||
local ifname = intf['ifname']
|
||||
local iw = iwinfo[iwinfo.type(ifname)]
|
||||
local labels = {
|
||||
channel = net:channel(),
|
||||
ssid = net:active_ssid(),
|
||||
bssid = net:active_bssid(),
|
||||
mode = net:active_mode(),
|
||||
ifname = net:ifname(),
|
||||
country = net:country(),
|
||||
frequency = net:frequency(),
|
||||
channel = iw.channel(ifname),
|
||||
ssid = iw.ssid(ifname),
|
||||
bssid = iw.bssid(ifname),
|
||||
mode = iw.mode(ifname),
|
||||
ifname = ifname,
|
||||
country = iw.country(ifname),
|
||||
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()
|
||||
for mac, station in pairs(assoclist) do
|
||||
local labels = {
|
||||
ifname = net: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
|
||||
else
|
||||
metric_wifi_network_up(labels, 0)
|
||||
local qc = iw.quality(ifname) or 0
|
||||
local qm = iw.quality_max(ifname) or 0
|
||||
local quality = 0
|
||||
if qc > 0 and qm > 0 then
|
||||
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)
|
||||
|
||||
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
|
||||
rv[#rv+1] = rd
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue