Skip to content

Commit 11375bf

Browse files
committed
Add network stats for endpoints
Signed-off-by: James Sturtevant <[email protected]>
1 parent b8f71ac commit 11375bf

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

hcn/hnsv1_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,39 @@ func TestEndpointGetAll(t *testing.T) {
7979
}
8080
}
8181

82+
func TestEndpointStatsAll(t *testing.T) {
83+
network, err := CreateTestNetwork()
84+
if err != nil {
85+
t.Fatal(err)
86+
}
87+
88+
Endpoint := &hcsshim.HNSEndpoint{
89+
Name: NatTestEndpointName,
90+
}
91+
92+
Endpoint, err = network.CreateEndpoint(Endpoint)
93+
if err != nil {
94+
t.Fatal(err)
95+
}
96+
97+
epList, err := hcsshim.HNSListEndpointRequest()
98+
if err != nil {
99+
t.Fatal(err)
100+
}
101+
102+
for _, e := range epList {
103+
_, err := hcsshim.GetHNSEndpointStats(e.Id)
104+
if err != nil {
105+
t.Fatal(err)
106+
}
107+
}
108+
109+
_, err = network.Delete()
110+
if err != nil {
111+
t.Fatal(err)
112+
}
113+
}
114+
82115
func TestNetworkGetAll(t *testing.T) {
83116
_, err := hcsshim.HNSListNetworkRequest("GET", "", "")
84117
if err != nil {

hnsendpoint.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
// HNSEndpoint represents a network endpoint in HNS
88
type HNSEndpoint = hns.HNSEndpoint
99

10+
// HNSEndpointStats represent the stats for an networkendpoint in HNS
11+
type HNSEndpointStats = hns.EndpointStats
12+
1013
// Namespace represents a Compartment.
1114
type Namespace = hns.Namespace
1215

@@ -108,3 +111,8 @@ func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
108111
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
109112
return hns.GetHNSEndpointByName(endpointName)
110113
}
114+
115+
// GetHNSEndpointStats gets the endpoint stats by ID
116+
func GetHNSEndpointStats(endpointName string) (*HNSEndpointStats, error) {
117+
return hns.GetHNSEndpointStats(endpointName)
118+
}

internal/hns/hnsendpoint.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ type EndpointResquestResponse struct {
5858
Error string
5959
}
6060

61+
// EndpointStats is the object that has stats for a given endpoint
62+
type EndpointStats struct {
63+
BytesReceived uint64 `json:"BytesReceived"`
64+
BytesSent uint64 `json:"BytesSent"`
65+
DroppedPacketsIncoming uint64 `json:"DroppedPacketsIncoming"`
66+
DroppedPacketsOutgoing uint64 `json:"DroppedPacketsOutgoing"`
67+
EndpointID string `json:"EndpointId"`
68+
InstanceID string `json:"InstanceId"`
69+
PacketsReceived uint64 `json:"PacketsReceived"`
70+
PacketsSent uint64 `json:"PacketsSent"`
71+
}
72+
6173
// HNSEndpointRequest makes a HNS call to modify/query a network endpoint
6274
func HNSEndpointRequest(method, path, request string) (*HNSEndpoint, error) {
6375
endpoint := &HNSEndpoint{}
@@ -80,11 +92,27 @@ func HNSListEndpointRequest() ([]HNSEndpoint, error) {
8092
return endpoint, nil
8193
}
8294

95+
// hnsEndpointStatsRequest makes a HNS call to query the stats for a given endpoint ID
96+
func hnsEndpointStatsRequest(id string) (*EndpointStats, error) {
97+
var stats EndpointStats
98+
err := hnsCall("GET", "/endpointstats/"+id, "", &stats)
99+
if err != nil {
100+
return nil, err
101+
}
102+
103+
return &stats, nil
104+
}
105+
83106
// GetHNSEndpointByID get the Endpoint by ID
84107
func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
85108
return HNSEndpointRequest("GET", endpointID, "")
86109
}
87110

111+
// GetHNSEndpointStats get the stats for a n Endpoint by ID
112+
func GetHNSEndpointStats(endpointID string) (*EndpointStats, error) {
113+
return hnsEndpointStatsRequest(endpointID)
114+
}
115+
88116
// GetHNSEndpointByName gets the endpoint filtered by Name
89117
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
90118
hnsResponse, err := HNSListEndpointRequest()

0 commit comments

Comments
 (0)