Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
docker/engine-api example to extract JSON docker-stats
package main
import (
"fmt"
"io/ioutil"
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
"golang.org/x/net/context"
)
func main() {
cli, err := client.NewEnvClient()
if err != nil {
panic(err)
}
options := types.ContainerListOptions{All: false}
containers, err := cli.ContainerList(context.Background(), options)
if err != nil {
panic(err)
}
for _, c := range containers {
body, _ := cli.ContainerStats(context.Background(), c.ID, false)
defer body.Close()
content, _ := ioutil.ReadAll(body)
fmt.Printf(string(content))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.