-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (51 loc) · 1.29 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"github.com/gusantoniassi/navegante/core/entity"
"github.com/gusantoniassi/navegante/gateway/containergateway"
"github.com/gusantoniassi/navegante/gateway/dockergateway"
"github.com/docker/docker/client"
)
func main() {
// Example Docker client implementation
// @TODO: remove this method
c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
cGw := containergateway.Container(dockergateway.NewGateway(c))
//data, err := getContainers(cGw)
data, err := getStats(cGw)
if err != nil {
panic(err)
}
//marshalled, _ := json.Marshal(data)
//fmt.Printf("%s\n", marshalled)
for _, v := range data {
fmt.Printf(
"ID: %s\n"+
"CPU%%: %.2f\n"+
"Mem%%: %.2f\n"+
"Mem usg/lim: %d/%d\n"+
"Net I/O: %d/%d\n"+
"Block I/O: %d/%d\n",
v.ContainerID[:12],
v.CPUPercent,
v.MemoryPercent,
v.MemoryUsage,
v.MemoryTotal,
v.NetworkInput,
v.NetworkOutput,
v.BlockRead,
v.BlockWrite,
)
}
}
func getContainers(cGw containergateway.Container) ([]*entity.Container, error) {
containers, err := cGw.ContainerGetAll()
return containers, err
}
func getStats(cGw containergateway.Container) ([]*entity.Stat, error) {
stats, err := cGw.ContainerStatsAll()
return stats, err
}