ctop/main.go

57 lines
987 B
Go
Raw Normal View History

package main
import (
"os"
"github.com/fsouza/go-dockerclient"
)
func runningCIDs(client *docker.Client) (running []string) {
filters := make(map[string][]string)
filters["status"] = []string{"running"}
opts := docker.ListContainersOptions{
Filters: filters,
}
containers, err := client.ListContainers(opts)
if err != nil {
panic(err)
}
for _, c := range containers {
running = append(running, c.ID[:12])
}
return running
}
func main() {
var containers []string
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)
}
// Default to all running containers
if len(os.Args) < 2 {
containers = runningCIDs(client)
} else {
containers = os.Args[1:]
}
2016-12-26 18:39:15 +00:00
g := &Grid{0, make(map[string]*Container)}
for _, c := range containers {
g.AddContainer(c)
}
for _, c := range g.containers {
c.Collect(client)
}
Display(g)
}