Skip to content

Instantly share code, notes, and snippets.

@ChristianKniep
Last active April 20, 2020 18:20
Show Gist options
  • Save ChristianKniep/2b13b0a01ebd99a82e0b7ffb2710c624 to your computer and use it in GitHub Desktop.
Save ChristianKniep/2b13b0a01ebd99a82e0b7ffb2710c624 to your computer and use it in GitHub Desktop.
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