From c8e98c4c3c7b90a89c51b202d22da0321c736877 Mon Sep 17 00:00:00 2001 From: Bouke van der Bijl Date: Tue, 19 Aug 2025 16:48:48 +0200 Subject: [PATCH] Add wifi packet received and transmitted metrics Signed-off-by: Bouke van der Bijl --- collector/fixtures/e2e-64k-page-output.txt | 8 ++++ collector/fixtures/e2e-output.txt | 8 ++++ collector/wifi_linux.go | 52 +++++++++++++++++----- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index 1914288e..0491e680 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -3356,6 +3356,10 @@ node_wifi_station_receive_bits_per_second{device="wlan0",mac_address="aa:bb:cc:d # TYPE node_wifi_station_receive_bytes_total counter node_wifi_station_receive_bytes_total{device="wlan0",mac_address="01:02:03:04:05:06"} 0 node_wifi_station_receive_bytes_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 0 +# HELP node_wifi_station_received_packets_total The total number of packets received by a station. +# TYPE node_wifi_station_received_packets_total counter +node_wifi_station_received_packets_total{device="wlan0",mac_address="01:02:03:04:05:06"} 0 +node_wifi_station_received_packets_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 0 # HELP node_wifi_station_signal_dbm The current WiFi signal strength, in decibel-milliwatts (dBm). # TYPE node_wifi_station_signal_dbm gauge node_wifi_station_signal_dbm{device="wlan0",mac_address="01:02:03:04:05:06"} -26 @@ -3376,6 +3380,10 @@ node_wifi_station_transmit_failed_total{device="wlan0",mac_address="aa:bb:cc:dd: # TYPE node_wifi_station_transmit_retries_total counter node_wifi_station_transmit_retries_total{device="wlan0",mac_address="01:02:03:04:05:06"} 20 node_wifi_station_transmit_retries_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 10 +# HELP node_wifi_station_transmitted_packets_total The total number of packets transmitted by a station. +# TYPE node_wifi_station_transmitted_packets_total counter +node_wifi_station_transmitted_packets_total{device="wlan0",mac_address="01:02:03:04:05:06"} 0 +node_wifi_station_transmitted_packets_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 0 # HELP node_xfrm_acquire_error_packets_total State hasn’t been fully acquired before use # TYPE node_xfrm_acquire_error_packets_total counter node_xfrm_acquire_error_packets_total 24532 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 634386da..ec7b932c 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -3378,6 +3378,10 @@ node_wifi_station_receive_bits_per_second{device="wlan0",mac_address="aa:bb:cc:d # TYPE node_wifi_station_receive_bytes_total counter node_wifi_station_receive_bytes_total{device="wlan0",mac_address="01:02:03:04:05:06"} 0 node_wifi_station_receive_bytes_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 0 +# HELP node_wifi_station_received_packets_total The total number of packets received by a station. +# TYPE node_wifi_station_received_packets_total counter +node_wifi_station_received_packets_total{device="wlan0",mac_address="01:02:03:04:05:06"} 0 +node_wifi_station_received_packets_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 0 # HELP node_wifi_station_signal_dbm The current WiFi signal strength, in decibel-milliwatts (dBm). # TYPE node_wifi_station_signal_dbm gauge node_wifi_station_signal_dbm{device="wlan0",mac_address="01:02:03:04:05:06"} -26 @@ -3398,6 +3402,10 @@ node_wifi_station_transmit_failed_total{device="wlan0",mac_address="aa:bb:cc:dd: # TYPE node_wifi_station_transmit_retries_total counter node_wifi_station_transmit_retries_total{device="wlan0",mac_address="01:02:03:04:05:06"} 20 node_wifi_station_transmit_retries_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 10 +# HELP node_wifi_station_transmitted_packets_total The total number of packets transmitted by a station. +# TYPE node_wifi_station_transmitted_packets_total counter +node_wifi_station_transmitted_packets_total{device="wlan0",mac_address="01:02:03:04:05:06"} 0 +node_wifi_station_transmitted_packets_total{device="wlan0",mac_address="aa:bb:cc:dd:ee:ff"} 0 # HELP node_xfrm_acquire_error_packets_total State hasn’t been fully acquired before use # TYPE node_xfrm_acquire_error_packets_total counter node_xfrm_acquire_error_packets_total 24532 diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index c84cdd71..358fb0cd 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go @@ -33,16 +33,18 @@ type wifiCollector struct { interfaceFrequencyHertz *prometheus.Desc stationInfo *prometheus.Desc - stationConnectedSecondsTotal *prometheus.Desc - stationInactiveSeconds *prometheus.Desc - stationReceiveBitsPerSecond *prometheus.Desc - stationTransmitBitsPerSecond *prometheus.Desc - stationReceiveBytesTotal *prometheus.Desc - stationTransmitBytesTotal *prometheus.Desc - stationSignalDBM *prometheus.Desc - stationTransmitRetriesTotal *prometheus.Desc - stationTransmitFailedTotal *prometheus.Desc - stationBeaconLossTotal *prometheus.Desc + stationConnectedSecondsTotal *prometheus.Desc + stationInactiveSeconds *prometheus.Desc + stationReceiveBitsPerSecond *prometheus.Desc + stationTransmitBitsPerSecond *prometheus.Desc + stationReceiveBytesTotal *prometheus.Desc + stationTransmitBytesTotal *prometheus.Desc + stationSignalDBM *prometheus.Desc + stationTransmitRetriesTotal *prometheus.Desc + stationTransmitFailedTotal *prometheus.Desc + stationBeaconLossTotal *prometheus.Desc + stationTransmittedPacketsTotal *prometheus.Desc + stationReceivedPacketsTotal *prometheus.Desc logger *slog.Logger } @@ -159,6 +161,20 @@ func NewWifiCollector(logger *slog.Logger) (Collector, error) { labels, nil, ), + + stationTransmittedPacketsTotal: prometheus.NewDesc( + prometheus.BuildFQName(namespace, subsystem, "station_transmitted_packets_total"), + "The total number of packets transmitted by a station.", + labels, + nil, + ), + + stationReceivedPacketsTotal: prometheus.NewDesc( + prometheus.BuildFQName(namespace, subsystem, "station_received_packets_total"), + "The total number of packets received by a station.", + labels, + nil, + ), logger: logger, }, nil } @@ -325,6 +341,22 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s device, info.HardwareAddr.String(), ) + + ch <- prometheus.MustNewConstMetric( + c.stationTransmittedPacketsTotal, + prometheus.CounterValue, + float64(info.TransmittedPackets), + device, + info.HardwareAddr.String(), + ) + + ch <- prometheus.MustNewConstMetric( + c.stationReceivedPacketsTotal, + prometheus.CounterValue, + float64(info.ReceivedPackets), + device, + info.HardwareAddr.String(), + ) } func mHzToHz(mHz int) float64 {