-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_simplelog_test.go
36 lines (33 loc) · 1.23 KB
/
example_simplelog_test.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
package owlk8s_test
import (
"fmt"
"github.com/est357/owlk8s"
"time"
)
// Example_simpleLog shows basic usage of the library
func Example_simpleLog() {
// timeInterval is what gives the resolution of the metrics.
// A lower value yields higher resolution. It also depends on how much
// traffic you are getting meaning that with higher traffic you may want
// higher resolution. You could set this as an env variable.
var timeInterval time.Duration = 1000
results := make(owlk8s.ResMap)
owlk8s.NewController(results).Run()
for {
for k, v := range results {
// Always check the Results function value is not nil
// because the controller might have NOT found any
// svc endpoints to monitor yet.
if v.Results != nil {
// v.Results() writes to the user's map the following
// keys: "duration", "requests", "err4", "err5".
// Duration comes in us, here we convert to ms.
res := make(map[string]*uint64)
v.Results(res)
fmt.Printf("IP: %s, OwnerObj: %s, Pod: %s, NS: %s, SVC: %s, Duration: %d, Requests: %d, Err4: %d, Err5: %d\n", k,
v.OwnerName, v.PodName, v.NS, v.SvcName, *res["duration"]/1000, *res["requests"], *res["err4"], *res["err5"])
}
}
time.Sleep(time.Millisecond * timeInterval)
}
}