runc/nsinit/stats.go

40 lines
674 B
Go
Raw Normal View History

package main
import (
"encoding/json"
"fmt"
"log"
"github.com/codegangsta/cli"
2014-06-10 23:14:16 +08:00
"github.com/docker/libcontainer"
)
var statsCommand = cli.Command{
Name: "stats",
Usage: "display statistics for the container",
Action: statsAction,
}
func statsAction(context *cli.Context) {
factory, err := libcontainer.New(context.GlobalString("root"), nil)
if err != nil {
log.Fatal(err)
}
container, err := factory.Load(context.Args().First())
if err != nil {
log.Fatal(err)
}
stats, err := container.Stats()
if err != nil {
log.Fatal(err)
}
data, jerr := json.MarshalIndent(stats, "", "\t")
if err != nil {
log.Fatal(jerr)
}
fmt.Printf("%s", data)
}