forked from rokett/Citrix-NetScaler-Exporter
/
get_interface_stats.go
37 lines (30 loc) · 1.1 KB
/
get_interface_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package netscaler
import (
"encoding/json"
"github.com/pkg/errors"
)
// InterfaceStats represents the data returned from the /stat/interface Nitro API endpoint
type InterfaceStats struct {
ID string `json:"id"`
TotalReceivedBytes string `json:"totrxbytes"`
TotalTransmitBytes string `json:"tottxbytes"`
TotalReceivedPackets string `json:"totrxpkts"`
TotalTransmitPackets string `json:"tottxpkts"`
JumboPacketsReceived string `json:"jumbopktsreceived"`
JumboPacketsTransmitted string `json:"jumbopktstransmitted"`
ErrorPacketsReceived string `json:"errpktrx"`
Alias string `json:"interfacealias"`
}
// GetInterfaceStats queries the Nitro API for interface stats
func GetInterfaceStats(c *NitroClient, querystring string) (NSAPIResponse, error) {
stats, err := c.GetStats("interface", querystring)
if err != nil {
return NSAPIResponse{}, err
}
var response = new(NSAPIResponse)
err = json.Unmarshal(stats, &response)
if err != nil {
return NSAPIResponse{}, errors.Wrap(err, "error unmarshalling response body")
}
return *response, nil
}