Make wifi collector fail gracefully if metrics not available

This commit is contained in:
Matt Layher 2017-01-12 12:41:35 -05:00
commit d3089f2ce8
No known key found for this signature in database
GPG key ID: 77BFE531397EDE94
6 changed files with 101 additions and 26 deletions

View file

@ -1,5 +1,15 @@
package wifi
import (
"errors"
)
var (
// errNotStation is returned when attempting to query station info for
// an interface which is not a station.
errNotStation = errors.New("interface is not a station")
)
// A Client is a type which can access WiFi device actions and statistics
// using operating system-specific operations.
type Client struct {
@ -18,6 +28,11 @@ func New() (*Client, error) {
}, nil
}
// Close releases resources used by a Client.
func (c *Client) Close() error {
return c.c.Close()
}
// Interfaces returns a list of the system's WiFi network interfaces.
func (c *Client) Interfaces() ([]*Interface, error) {
return c.c.Interfaces()
@ -26,11 +41,16 @@ func (c *Client) Interfaces() ([]*Interface, error) {
// StationInfo retrieves statistics about a WiFi interface operating in
// station mode.
func (c *Client) StationInfo(ifi *Interface) (*StationInfo, error) {
if ifi.Type != InterfaceTypeStation {
return nil, errNotStation
}
return c.c.StationInfo(ifi)
}
// An osClient is the operating system-specific implementation of Client.
type osClient interface {
Close() error
Interfaces() ([]*Interface, error)
StationInfo(ifi *Interface) (*StationInfo, error)
}