ctop/main.go

45 lines
750 B
Go
Raw Normal View History

package main
import (
"os"
"github.com/fsouza/go-dockerclient"
)
2016-12-27 02:24:02 +00:00
func getContainers(client *docker.Client) []docker.APIContainers {
filters := make(map[string][]string)
filters["status"] = []string{"running"}
opts := docker.ListContainersOptions{
Filters: filters,
}
containers, err := client.ListContainers(opts)
if err != nil {
panic(err)
}
2016-12-27 02:24:02 +00:00
return containers
}
func main() {
2016-12-25 19:07:42 +00:00
dockerhost := os.Getenv("DOCKER_HOST")
if dockerhost == "" {
dockerhost = "unix:///var/run/docker.sock"
}
client, err := docker.NewClient(dockerhost)
if err != nil {
panic(err)
}
2016-12-30 21:14:07 +00:00
g := NewGrid()
2016-12-27 02:24:02 +00:00
for _, c := range getContainers(client) {
2016-12-30 21:14:07 +00:00
g.containers.Add(c)
}
2016-12-30 21:14:07 +00:00
for _, c := range g.containers.All() {
c.Collect(client)
}
Display(g)
}