aboutsummaryrefslogtreecommitdiff
path: root/collector/wifi_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'collector/wifi_linux.go')
-rw-r--r--collector/wifi_linux.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go
index b4b3759..076982d 100644
--- a/collector/wifi_linux.go
+++ b/collector/wifi_linux.go
@@ -17,6 +17,7 @@ package collector
17 17
18import ( 18import (
19 "encoding/json" 19 "encoding/json"
20 "errors"
20 "fmt" 21 "fmt"
21 "io/ioutil" 22 "io/ioutil"
22 "os" 23 "os"
@@ -167,11 +168,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
167 stat, err := newWifiStater(*collectorWifi) 168 stat, err := newWifiStater(*collectorWifi)
168 if err != nil { 169 if err != nil {
169 // Cannot access wifi metrics, report no error. 170 // Cannot access wifi metrics, report no error.
170 if os.IsNotExist(err) { 171 if errors.Is(err, os.ErrNotExist) {
171 level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") 172 level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system")
172 return ErrNoData 173 return ErrNoData
173 } 174 }
174 if os.IsPermission(err) { 175 if errors.Is(err, os.ErrPermission) {
175 level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") 176 level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics")
176 return ErrNoData 177 return ErrNoData
177 } 178 }
@@ -201,14 +202,14 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
201 ) 202 )
202 203
203 // When a statistic is not available for a given interface, package wifi 204 // When a statistic is not available for a given interface, package wifi
204 // returns an error compatible with os.IsNotExist. We leverage this to 205 // returns a os.ErrNotExist error. We leverage this to only export
205 // only export metrics which are actually valid for given interface types. 206 // metrics which are actually valid for given interface types.
206 207
207 bss, err := stat.BSS(ifi) 208 bss, err := stat.BSS(ifi)
208 switch { 209 switch {
209 case err == nil: 210 case err == nil:
210 c.updateBSSStats(ch, ifi.Name, bss) 211 c.updateBSSStats(ch, ifi.Name, bss)
211 case os.IsNotExist(err): 212 case errors.Is(err, os.ErrNotExist):
212 level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) 213 level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name)
213 default: 214 default:
214 return fmt.Errorf("failed to retrieve BSS for device %s: %v", 215 return fmt.Errorf("failed to retrieve BSS for device %s: %v",
@@ -221,7 +222,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
221 for _, station := range stations { 222 for _, station := range stations {
222 c.updateStationStats(ch, ifi.Name, station) 223 c.updateStationStats(ch, ifi.Name, station)
223 } 224 }
224 case os.IsNotExist(err): 225 case errors.Is(err, os.ErrNotExist):
225 level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) 226 level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name)
226 default: 227 default:
227 return fmt.Errorf("failed to retrieve station info for device %q: %v", 228 return fmt.Errorf("failed to retrieve station info for device %q: %v",