diff options
author | neiledgar <neil.edgar@btinternet.com> | 2018-07-16 15:02:25 +0100 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2018-07-16 16:02:25 +0200 |
commit | 7e4d9bd1501f315504808d70ac5e80d77fd7660c (patch) | |
tree | 21e39cde7a8a007a140a9832f9c2394f6fc720de /collector/wifi_linux.go | |
parent | 9b97f44a704c9c31e45c864c105643e6b197abad (diff) | |
download | prometheus_node_collector-7e4d9bd1501f315504808d70ac5e80d77fd7660c.tar.bz2 prometheus_node_collector-7e4d9bd1501f315504808d70ac5e80d77fd7660c.tar.xz prometheus_node_collector-7e4d9bd1501f315504808d70ac5e80d77fd7660c.zip |
Update wifi stats to support multiple stations (#977) (#980)
Signed-off-by: neiledgar <neil.edgar@btinternet.com>
Diffstat (limited to 'collector/wifi_linux.go')
-rw-r--r-- | collector/wifi_linux.go | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index b3a1cf4..c2855a1 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go | |||
@@ -55,7 +55,7 @@ type wifiStater interface { | |||
55 | BSS(ifi *wifi.Interface) (*wifi.BSS, error) | 55 | BSS(ifi *wifi.Interface) (*wifi.BSS, error) |
56 | Close() error | 56 | Close() error |
57 | Interfaces() ([]*wifi.Interface, error) | 57 | Interfaces() ([]*wifi.Interface, error) |
58 | StationInfo(ifi *wifi.Interface) (*wifi.StationInfo, error) | 58 | StationInfo(ifi *wifi.Interface) ([]*wifi.StationInfo, error) |
59 | } | 59 | } |
60 | 60 | ||
61 | // NewWifiCollector returns a new Collector exposing Wifi statistics. | 61 | // NewWifiCollector returns a new Collector exposing Wifi statistics. |
@@ -65,14 +65,14 @@ func NewWifiCollector() (Collector, error) { | |||
65 | ) | 65 | ) |
66 | 66 | ||
67 | var ( | 67 | var ( |
68 | labels = []string{"device"} | 68 | labels = []string{"device", "mac_address"} |
69 | ) | 69 | ) |
70 | 70 | ||
71 | return &wifiCollector{ | 71 | return &wifiCollector{ |
72 | interfaceFrequencyHertz: prometheus.NewDesc( | 72 | interfaceFrequencyHertz: prometheus.NewDesc( |
73 | prometheus.BuildFQName(namespace, subsystem, "interface_frequency_hertz"), | 73 | prometheus.BuildFQName(namespace, subsystem, "interface_frequency_hertz"), |
74 | "The current frequency a WiFi interface is operating at, in hertz.", | 74 | "The current frequency a WiFi interface is operating at, in hertz.", |
75 | labels, | 75 | []string{"device"}, |
76 | nil, | 76 | nil, |
77 | ), | 77 | ), |
78 | 78 | ||
@@ -193,10 +193,12 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
193 | ifi.Name, err) | 193 | ifi.Name, err) |
194 | } | 194 | } |
195 | 195 | ||
196 | info, err := stat.StationInfo(ifi) | 196 | stations, err := stat.StationInfo(ifi) |
197 | switch { | 197 | switch { |
198 | case err == nil: | 198 | case err == nil: |
199 | c.updateStationStats(ch, ifi.Name, info) | 199 | for _, station := range stations { |
200 | c.updateStationStats(ch, ifi.Name, station) | ||
201 | } | ||
200 | case os.IsNotExist(err): | 202 | case os.IsNotExist(err): |
201 | log.Debugf("station information not found for wifi device %q", ifi.Name) | 203 | log.Debugf("station information not found for wifi device %q", ifi.Name) |
202 | default: | 204 | default: |
@@ -227,6 +229,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
227 | prometheus.CounterValue, | 229 | prometheus.CounterValue, |
228 | info.Connected.Seconds(), | 230 | info.Connected.Seconds(), |
229 | device, | 231 | device, |
232 | info.HardwareAddr.String(), | ||
230 | ) | 233 | ) |
231 | 234 | ||
232 | ch <- prometheus.MustNewConstMetric( | 235 | ch <- prometheus.MustNewConstMetric( |
@@ -234,6 +237,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
234 | prometheus.GaugeValue, | 237 | prometheus.GaugeValue, |
235 | info.Inactive.Seconds(), | 238 | info.Inactive.Seconds(), |
236 | device, | 239 | device, |
240 | info.HardwareAddr.String(), | ||
237 | ) | 241 | ) |
238 | 242 | ||
239 | ch <- prometheus.MustNewConstMetric( | 243 | ch <- prometheus.MustNewConstMetric( |
@@ -241,6 +245,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
241 | prometheus.GaugeValue, | 245 | prometheus.GaugeValue, |
242 | float64(info.ReceiveBitrate), | 246 | float64(info.ReceiveBitrate), |
243 | device, | 247 | device, |
248 | info.HardwareAddr.String(), | ||
244 | ) | 249 | ) |
245 | 250 | ||
246 | ch <- prometheus.MustNewConstMetric( | 251 | ch <- prometheus.MustNewConstMetric( |
@@ -248,6 +253,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
248 | prometheus.GaugeValue, | 253 | prometheus.GaugeValue, |
249 | float64(info.TransmitBitrate), | 254 | float64(info.TransmitBitrate), |
250 | device, | 255 | device, |
256 | info.HardwareAddr.String(), | ||
251 | ) | 257 | ) |
252 | 258 | ||
253 | ch <- prometheus.MustNewConstMetric( | 259 | ch <- prometheus.MustNewConstMetric( |
@@ -255,6 +261,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
255 | prometheus.GaugeValue, | 261 | prometheus.GaugeValue, |
256 | float64(info.Signal), | 262 | float64(info.Signal), |
257 | device, | 263 | device, |
264 | info.HardwareAddr.String(), | ||
258 | ) | 265 | ) |
259 | 266 | ||
260 | ch <- prometheus.MustNewConstMetric( | 267 | ch <- prometheus.MustNewConstMetric( |
@@ -262,6 +269,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
262 | prometheus.CounterValue, | 269 | prometheus.CounterValue, |
263 | float64(info.TransmitRetries), | 270 | float64(info.TransmitRetries), |
264 | device, | 271 | device, |
272 | info.HardwareAddr.String(), | ||
265 | ) | 273 | ) |
266 | 274 | ||
267 | ch <- prometheus.MustNewConstMetric( | 275 | ch <- prometheus.MustNewConstMetric( |
@@ -269,6 +277,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
269 | prometheus.CounterValue, | 277 | prometheus.CounterValue, |
270 | float64(info.TransmitFailed), | 278 | float64(info.TransmitFailed), |
271 | device, | 279 | device, |
280 | info.HardwareAddr.String(), | ||
272 | ) | 281 | ) |
273 | 282 | ||
274 | ch <- prometheus.MustNewConstMetric( | 283 | ch <- prometheus.MustNewConstMetric( |
@@ -276,6 +285,7 @@ func (c *wifiCollector) updateStationStats(ch chan<- prometheus.Metric, device s | |||
276 | prometheus.CounterValue, | 285 | prometheus.CounterValue, |
277 | float64(info.BeaconLoss), | 286 | float64(info.BeaconLoss), |
278 | device, | 287 | device, |
288 | info.HardwareAddr.String(), | ||
279 | ) | 289 | ) |
280 | } | 290 | } |
281 | 291 | ||
@@ -346,13 +356,13 @@ func (s *mockWifiStater) Interfaces() ([]*wifi.Interface, error) { | |||
346 | return ifis, nil | 356 | return ifis, nil |
347 | } | 357 | } |
348 | 358 | ||
349 | func (s *mockWifiStater) StationInfo(ifi *wifi.Interface) (*wifi.StationInfo, error) { | 359 | func (s *mockWifiStater) StationInfo(ifi *wifi.Interface) ([]*wifi.StationInfo, error) { |
350 | p := filepath.Join(ifi.Name, "stationinfo.json") | 360 | p := filepath.Join(ifi.Name, "stationinfo.json") |
351 | 361 | ||
352 | var info wifi.StationInfo | 362 | var stations []*wifi.StationInfo |
353 | if err := s.unmarshalJSONFile(p, &info); err != nil { | 363 | if err := s.unmarshalJSONFile(p, &stations); err != nil { |
354 | return nil, err | 364 | return nil, err |
355 | } | 365 | } |
356 | 366 | ||
357 | return &info, nil | 367 | return stations, nil |
358 | } | 368 | } |