Add basic counters

This commit is contained in:
Michael Crosby
2015-11-05 16:16:11 -08:00
parent 05683fb0ee
commit 2af0f297fe
4 changed files with 28 additions and 0 deletions

View File

@@ -1,14 +1,18 @@
package main
import (
"log"
"os"
"os/signal"
"runtime"
"syscall"
"time"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/crosbymichael/containerd"
"github.com/opencontainers/runc/libcontainer/utils"
"github.com/rcrowley/go-metrics"
)
var DaemonCommand = cli.Command{
@@ -26,6 +30,17 @@ var DaemonCommand = cli.Command{
},
},
Action: func(context *cli.Context) {
if context.GlobalBool("debug") {
l := log.New(os.Stdout, "[containerd] ", log.LstdFlags)
goRoutineCounter := metrics.NewMeter()
metrics.DefaultRegistry.Register("goroutines", goRoutineCounter)
go func() {
for range time.Tick(30 * time.Second) {
goRoutineCounter.Mark(int64(runtime.NumGoroutine()))
}
}()
go metrics.Log(metrics.DefaultRegistry, 60*time.Second, l)
}
if err := daemon(context.String("state-dir"), 20, context.Int("buffer-size")); err != nil {
logrus.Fatal(err)
}

View File

@@ -28,6 +28,7 @@ func main() {
}
app.Flags = []cli.Flag{
cli.BoolFlag{Name: "debug", Usage: "enable debug output in the logs"},
// cli.StringFlag{Name: "metrics", Value: "stdout", Usage: "metrics file"},
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") {