88a993c54fdf0768fd6221e3c3986dc2797cb00b
[feed/packages.git] /
1 local ubus = require "ubus"
2 local bit = require "bit"
3
4 local function get_wifi_interfaces() -- based on hostapd_stations.lua
5 local u = ubus.connect()
6 local status = u:call("network.wireless", "status", {})
7 local interfaces = {}
8
9 for _, dev_table in pairs(status) do
10 for _, intf in ipairs(dev_table['interfaces']) do
11 table.insert(interfaces, intf['ifname'])
12 end
13 end
14
15 return interfaces
16 end
17
18 local function scrape()
19 local metric_hostapd_ubus_station_rrm_caps_link_measurement =
20 metric("hostapd_ubus_station_rrm_caps_link_measurement", "gauge")
21 local metric_hostapd_ubus_station_rrm_caps_neighbor_report =
22 metric("hostapd_ubus_station_rrm_caps_neighbor_report", "gauge")
23 local metric_hostapd_ubus_station_rrm_caps_beacon_report_passive =
24 metric("hostapd_ubus_station_rrm_caps_beacon_report_passive", "gauge")
25 local metric_hostapd_ubus_station_rrm_caps_beacon_report_active =
26 metric("hostapd_ubus_station_rrm_caps_beacon_report_active", "gauge")
27 local metric_hostapd_ubus_station_rrm_caps_beacon_report_table =
28 metric("hostapd_ubus_station_rrm_caps_beacon_report_table", "gauge")
29 local metric_hostapd_ubus_station_rrm_caps_lci_measurement =
30 metric("hostapd_ubus_station_rrm_caps_lci_measurement", "gauge")
31 local metric_hostapd_ubus_station_rrm_caps_ftm_range_report =
32 metric("hostapd_ubus_station_rrm_caps_ftm_range_report", "gauge")
33
34 local function evaluate_metrics(ifname, freq, station, vals)
35 local label_station = {
36 ifname = ifname,
37 freq = freq,
38 station = station
39 }
40 local rrm_caps_link_measurement = bit.band(bit.lshift(1, 0), vals['rrm'][1]) > 0 and 1 or 0
41 local rrm_caps_neighbor_report = bit.band(bit.lshift(1, 1), vals['rrm'][1]) > 0 and 1 or 0
42 local rrm_caps_beacon_report_passive = bit.band(bit.lshift(1, 4), vals['rrm'][1]) > 0 and 1 or 0
43 local rrm_caps_beacon_report_active = bit.band(bit.lshift(1, 5), vals['rrm'][1]) > 0 and 1 or 0
44 local rrm_caps_beacon_report_table = bit.band(bit.lshift(1, 6), vals['rrm'][1]) > 0 and 1 or 0
45 local rrm_caps_lci_measurement = bit.band(bit.lshift(1, 4), vals['rrm'][2]) > 0 and 1 or 0
46 local rrm_caps_ftm_range_report = bit.band(bit.lshift(1, 2), vals['rrm'][5]) > 0 and 1 or 0
47
48 metric_hostapd_ubus_station_rrm_caps_link_measurement(label_station, rrm_caps_link_measurement)
49 metric_hostapd_ubus_station_rrm_caps_neighbor_report(label_station, rrm_caps_neighbor_report)
50 metric_hostapd_ubus_station_rrm_caps_beacon_report_passive(label_station, rrm_caps_beacon_report_passive)
51 metric_hostapd_ubus_station_rrm_caps_beacon_report_active(label_station, rrm_caps_beacon_report_active)
52 metric_hostapd_ubus_station_rrm_caps_beacon_report_table(label_station, rrm_caps_beacon_report_table)
53
54 metric_hostapd_ubus_station_rrm_caps_lci_measurement(label_station, rrm_caps_lci_measurement)
55 metric_hostapd_ubus_station_rrm_caps_ftm_range_report(label_station, rrm_caps_ftm_range_report)
56 end
57
58 for _, ifname in ipairs(get_wifi_interfaces()) do
59 local u = ubus.connect()
60 local clients_call = u:call("hostapd." .. ifname, "get_clients", {})
61
62 for client, client_table in pairs(clients_call['clients']) do
63 evaluate_metrics(ifname, clients_call['freq'], client, client_table)
64 end
65 end
66 end
67
68 return { scrape = scrape }