From 2833865d766e3faf6920620e75783cf7b3475427 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 1 Oct 2021 15:05:50 +0200 Subject: accesspoint: improve prometheus wifi-collectors --- inventory/group_vars/accesspoints/vars.yml | 68 +++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'inventory/group_vars/accesspoints/vars.yml') diff --git a/inventory/group_vars/accesspoints/vars.yml b/inventory/group_vars/accesspoints/vars.yml index 8dc28aea..cb2307cd 100644 --- a/inventory/group_vars/accesspoints/vars.yml +++ b/inventory/group_vars/accesspoints/vars.yml @@ -145,8 +145,12 @@ openwrt_packages_add: - prometheus-node-exporter-lua-nat_traffic - prometheus-node-exporter-lua-netstat - prometheus-node-exporter-lua-openwrt - - prometheus-node-exporter-lua-wifi - - prometheus-node-exporter-lua-wifi_stations + ## we will install a custom version of these collectors, see below + #- prometheus-node-exporter-lua-wifi + #- prometheus-node-exporter-lua-wifi_stations + ## manually install dependencies for wifi-collectors + - libiwinfo-lua + - libubus-lua openwrt_mixin: /etc/sysctl.conf: @@ -198,6 +202,66 @@ openwrt_mixin: iptables -P FORWARD ACCEPT } + /usr/lib/lua/prometheus-collectors/wifi.lua: + mode: "0755" + content: | + -- This is a custom version of the upstream wifi and wifi_stations collectors. We want + -- to know the number of stations connected but for privacy and metric cardinality + -- reasons we don't care for MAC addresses and other details of all connected stations. + + local ubus = require "ubus" + local iwinfo = require "iwinfo" + + local function scrape() + 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_dbm","gauge") + local metric_wifi_network_signal = metric("wifi_network_signal_dbm","gauge") + local metric_wifi_stations = metric("wifi_stations", "gauge") + + local u = ubus.connect() + local status = u:call("network.wireless", "status", {}) + + for dev, dev_table in pairs(status) do + for _, intf in ipairs(dev_table['interfaces']) do + local ifname = intf['ifname'] + if ifname ~= nil then + local iw = iwinfo[iwinfo.type(ifname)] + local labels = { + 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, + } + + 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 + local stations = 0 + local assoclist = iw.assoclist(ifname) + for _, _ in pairs(assoclist) do + stations = stations + 1 + 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) + metric_wifi_stations(labels, stations) + end + end + end + end + + return { scrape = scrape } + /usr/bin/list-stations: mode: "0755" content: | -- cgit v1.2.3