mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-09 23:24:09 -08:00
Expand wifi collector for more interface types
This commit is contained in:
parent
8529cd3359
commit
2bfe410fb7
|
@ -2149,6 +2149,7 @@ node_textfile_scrape_error 0
|
||||||
# HELP node_wifi_interface_frequency_hertz The current frequency a WiFi interface is operating at, in hertz.
|
# HELP node_wifi_interface_frequency_hertz The current frequency a WiFi interface is operating at, in hertz.
|
||||||
# TYPE node_wifi_interface_frequency_hertz gauge
|
# TYPE node_wifi_interface_frequency_hertz gauge
|
||||||
node_wifi_interface_frequency_hertz{device="wlan0"} 2.412e+09
|
node_wifi_interface_frequency_hertz{device="wlan0"} 2.412e+09
|
||||||
|
node_wifi_interface_frequency_hertz{device="wlan1"} 2.412e+09
|
||||||
# HELP node_wifi_station_beacon_loss_total The total number of times a station has detected a beacon loss.
|
# HELP node_wifi_station_beacon_loss_total The total number of times a station has detected a beacon loss.
|
||||||
# TYPE node_wifi_station_beacon_loss_total counter
|
# TYPE node_wifi_station_beacon_loss_total counter
|
||||||
node_wifi_station_beacon_loss_total{device="wlan0"} 1
|
node_wifi_station_beacon_loss_total{device="wlan0"} 1
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
"type": 2,
|
"type": 2,
|
||||||
"frequency": 2412
|
"frequency": 2412
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "wlan1",
|
||||||
|
"type": 3,
|
||||||
|
"frequency": 2412
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": 10
|
"type": 10
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,11 +160,13 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ifi := range ifis {
|
for _, ifi := range ifis {
|
||||||
// Only collect metrics on stations for now
|
// Some virtual devices have no "name" and should be skipped.
|
||||||
if ifi.Type != wifi.InterfaceTypeStation {
|
if ifi.Name == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("probing wifi device %q with type %q", ifi.Name, ifi.Type)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.interfaceFrequencyHertz,
|
c.interfaceFrequencyHertz,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
|
@ -172,43 +174,49 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
ifi.Name,
|
ifi.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
bss, err := stat.BSS(ifi)
|
// When a statistic is not available for a given interface, package wifi
|
||||||
if err != nil {
|
// returns an error compatible with os.IsNotExist. We leverage this to
|
||||||
if os.IsNotExist(err) {
|
// only export metrics which are actually valid for given interface types.
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
bss, err := stat.BSS(ifi)
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
c.updateBSSStats(ch, ifi.Name, bss)
|
||||||
|
case os.IsNotExist(err):
|
||||||
|
log.Debugf("BSS information not found for wifi device %q", ifi.Name)
|
||||||
|
default:
|
||||||
return fmt.Errorf("failed to retrieve BSS for device %s: %v",
|
return fmt.Errorf("failed to retrieve BSS for device %s: %v",
|
||||||
ifi.Name, err)
|
ifi.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synthetic metric which provides WiFi station info, such as SSID, BSSID, etc.
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
|
||||||
c.stationInfo,
|
|
||||||
prometheus.GaugeValue,
|
|
||||||
1,
|
|
||||||
ifi.Name,
|
|
||||||
bss.BSSID.String(),
|
|
||||||
bss.SSID,
|
|
||||||
bssStatusMode(bss.Status),
|
|
||||||
)
|
|
||||||
|
|
||||||
info, err := stat.StationInfo(ifi)
|
info, err := stat.StationInfo(ifi)
|
||||||
if err != nil {
|
switch {
|
||||||
if os.IsNotExist(err) {
|
case err == nil:
|
||||||
continue
|
c.updateStationStats(ch, ifi.Name, info)
|
||||||
}
|
case os.IsNotExist(err):
|
||||||
|
log.Debugf("station information not found for wifi device %q", ifi.Name)
|
||||||
return fmt.Errorf("failed to retrieve station info for device %s: %v",
|
default:
|
||||||
|
return fmt.Errorf("failed to retrieve station info for device %q: %v",
|
||||||
ifi.Name, err)
|
ifi.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateStationStats(ch, ifi.Name, info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *wifiCollector) updateBSSStats(ch chan<- prometheus.Metric, device string, bss *wifi.BSS) {
|
||||||
|
// Synthetic metric which provides wifi station info, such as SSID, BSSID, etc.
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.stationInfo,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
1,
|
||||||
|
device,
|
||||||
|
bss.BSSID.String(),
|
||||||
|
bss.SSID,
|
||||||
|
bssStatusMode(bss.Status),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device string, info *wifi.StationInfo) {
|
func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device string, info *wifi.StationInfo) {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.stationConnectedSecondsTotal,
|
c.stationConnectedSecondsTotal,
|
||||||
|
|
Loading…
Reference in a new issue