Last active
April 20, 2020 18:20
-
-
Save ChristianKniep/2b13b0a01ebd99a82e0b7ffb2710c624 to your computer and use it in GitHub Desktop.
docker/engine-api example to extract JSON docker-stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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