2014-08-13 01:46:43 +08:00
|
|
|
package main
|
2014-06-05 07:46:30 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2014-06-10 23:14:16 +08:00
|
|
|
"github.com/docker/libcontainer"
|
2014-06-05 07:46:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var statsCommand = cli.Command{
|
|
|
|
Name: "stats",
|
|
|
|
Usage: "display statistics for the container",
|
|
|
|
Action: statsAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
func statsAction(context *cli.Context) {
|
2014-12-15 23:08:56 +08:00
|
|
|
factory, err := libcontainer.New(context.GlobalString("root"), nil)
|
2014-06-06 05:28:09 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:45:23 +08:00
|
|
|
container, err := factory.Load(context.Args().First())
|
2014-06-14 09:31:12 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:45:23 +08:00
|
|
|
stats, err := container.Stats()
|
2014-06-05 07:46:30 +08:00
|
|
|
if err != nil {
|
2014-06-27 07:25:55 +08:00
|
|
|
log.Fatal(err)
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|
2014-10-23 04:45:23 +08:00
|
|
|
data, jerr := json.MarshalIndent(stats, "", "\t")
|
2014-06-05 07:46:30 +08:00
|
|
|
if err != nil {
|
2014-10-23 04:45:23 +08:00
|
|
|
log.Fatal(jerr)
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|
2014-06-06 05:28:09 +08:00
|
|
|
|
2014-06-27 07:25:55 +08:00
|
|
|
fmt.Printf("%s", data)
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|