Make wifi collector fail gracefully if metrics not available
This commit is contained in:
parent
2884181cce
commit
d3089f2ce8
6 changed files with 101 additions and 26 deletions
20
vendor/github.com/mdlayher/wifi/client.go
generated
vendored
20
vendor/github.com/mdlayher/wifi/client.go
generated
vendored
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
13
vendor/github.com/mdlayher/wifi/client_linux.go
generated
vendored
13
vendor/github.com/mdlayher/wifi/client_linux.go
generated
vendored
|
|
@ -36,6 +36,7 @@ type client struct {
|
|||
// genl is an interface over generic netlink, so netlink interactions can
|
||||
// be stubbed in tests.
|
||||
type genl interface {
|
||||
Close() error
|
||||
GetFamily(name string) (genetlink.Family, error)
|
||||
Execute(m genetlink.Message, family uint16, flags netlink.HeaderFlags) ([]genetlink.Message, error)
|
||||
}
|
||||
|
|
@ -66,6 +67,11 @@ func initClient(c genl) (*client, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Close closes the client's generic netlink connection.
|
||||
func (c *client) Close() error {
|
||||
return c.c.Close()
|
||||
}
|
||||
|
||||
// Interfaces requests that nl80211 return a list of all WiFi interfaces present
|
||||
// on this system.
|
||||
func (c *client) Interfaces() ([]*Interface, error) {
|
||||
|
|
@ -117,7 +123,12 @@ func (c *client) StationInfo(ifi *Interface) (*StationInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(msgs) > 1 {
|
||||
switch len(msgs) {
|
||||
case 0:
|
||||
return nil, os.ErrNotExist
|
||||
case 1:
|
||||
break
|
||||
default:
|
||||
return nil, errMultipleMessages
|
||||
}
|
||||
|
||||
|
|
|
|||
5
vendor/github.com/mdlayher/wifi/client_others.go
generated
vendored
5
vendor/github.com/mdlayher/wifi/client_others.go
generated
vendored
|
|
@ -24,6 +24,11 @@ func newClient() (*client, error) {
|
|||
return nil, errUnimplemented
|
||||
}
|
||||
|
||||
// Close always returns an error.
|
||||
func (c *client) Close() error {
|
||||
return errUnimplemented
|
||||
}
|
||||
|
||||
// Interfaces always returns an error.
|
||||
func (c *client) Interfaces() ([]*Interface, error) {
|
||||
return nil, errUnimplemented
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue