You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.6 KiB

  1. local ubus = require "ubus"
  2. local iwinfo = require "iwinfo"
  3. local function scrape()
  4. local metric_wifi_stations = metric("wifi_stations", "gauge")
  5. local metric_wifi_station_signal = metric("wifi_station_signal_dbm","gauge")
  6. local metric_wifi_station_inactive = metric('wifi_station_inactive_milliseconds', 'gauge')
  7. local metric_wifi_station_exp_thr = metric('wifi_station_expected_throughput_kilobits_per_second', 'gauge')
  8. local metric_wifi_station_tx_bitrate = metric('wifi_station_transmit_kilobits_per_second', 'gauge')
  9. local metric_wifi_station_rx_bitrate = metric('wifi_station_receive_kilobits_per_second', 'gauge')
  10. local metric_wifi_station_tx_packets = metric("wifi_station_transmit_packets_total","counter")
  11. local metric_wifi_station_rx_packets = metric("wifi_station_receive_packets_total","counter")
  12. local metric_wifi_station_tx_bytes = metric('wifi_station_transmit_bytes_total', 'counter')
  13. local metric_wifi_station_rx_bytes = metric('wifi_station_receive_bytes_total', 'counter')
  14. local u = ubus.connect()
  15. local status = u:call("network.wireless", "status", {})
  16. for dev, dev_table in pairs(status) do
  17. for _, intf in ipairs(dev_table['interfaces']) do
  18. local ifname = intf['ifname']
  19. local iw = iwinfo[iwinfo.type(ifname)]
  20. local count = 0
  21. local assoclist = iw.assoclist(ifname)
  22. for mac, station in pairs(assoclist) do
  23. local labels = {
  24. ifname = ifname,
  25. mac = mac,
  26. }
  27. if station.signal and station.signal ~= 0 then
  28. metric_wifi_station_signal(labels, station.signal)
  29. end
  30. if station.inactive then
  31. metric_wifi_station_inactive(labels, station.inactive)
  32. end
  33. if station.expected_throughput and station.expected_throughput ~= 0 then
  34. metric_wifi_station_exp_thr(labels, station.expected_throughput)
  35. end
  36. if station.tx_rate and station.tx_rate ~= 0 then
  37. metric_wifi_station_tx_bitrate(labels, station.tx_rate)
  38. end
  39. if station.rx_rate and station.rx_rate ~= 0 then
  40. metric_wifi_station_rx_bitrate(labels, station.rx_rate)
  41. end
  42. metric_wifi_station_tx_packets(labels, station.tx_packets)
  43. metric_wifi_station_rx_packets(labels, station.rx_packets)
  44. if station.tx_bytes then
  45. metric_wifi_station_tx_bytes(labels, station.tx_bytes)
  46. end
  47. if station.rx_bytes then
  48. metric_wifi_station_rx_bytes(labels, station.rx_bytes)
  49. end
  50. count = count + 1
  51. end
  52. metric_wifi_stations({ifname = ifname}, count)
  53. end
  54. end
  55. end
  56. return { scrape = scrape }