2014-06-05 07:46:30 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
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-06-06 05:28:09 +08:00
|
|
|
container, err := loadContainer()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-27 07:25:55 +08:00
|
|
|
state, err := libcontainer.GetState(dataPath)
|
2014-06-14 09:31:12 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-27 04:49:02 +08:00
|
|
|
stats, err := libcontainer.GetStats(container, state)
|
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-06-27 07:25:55 +08:00
|
|
|
data, err := json.MarshalIndent(stats, "", "\t")
|
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-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
|
|
|
}
|