From 2af0f297fea6e5d8e44d6aee2ed8d25f0001f73a Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 5 Nov 2015 16:16:11 -0800 Subject: [PATCH] Add basic counters --- .gitignore | 1 + containerd/daemon.go | 15 +++++++++++++++ containerd/main.go | 1 + supervisor.go | 11 +++++++++++ 4 files changed, 28 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e977afa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +containerd/containerd diff --git a/containerd/daemon.go b/containerd/daemon.go index 3d6b66c..2f926f8 100644 --- a/containerd/daemon.go +++ b/containerd/daemon.go @@ -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) } diff --git a/containerd/main.go b/containerd/main.go index bace1c2..9480d35 100644 --- a/containerd/main.go +++ b/containerd/main.go @@ -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") { diff --git a/supervisor.go b/supervisor.go index 5c40dc9..a6801df 100644 --- a/supervisor.go +++ b/supervisor.go @@ -3,8 +3,14 @@ package containerd import ( "os" "sync" + "time" "github.com/Sirupsen/logrus" + "github.com/rcrowley/go-metrics" +) + +var ( + containerStartTimer = metrics.NewTimer() ) // NewSupervisor returns an initialized Process supervisor. @@ -12,6 +18,8 @@ func NewSupervisor(stateDir string, concurrency int) (*Supervisor, error) { if err := os.MkdirAll(stateDir, 0755); err != nil { return nil, err } + // register counters + metrics.DefaultRegistry.Register("container-start-time", containerStartTimer) runtime, err := NewRuntime(stateDir) if err != nil { return nil, err @@ -93,9 +101,11 @@ func (s *Supervisor) worker(id int) { s.workerGroup.Done() logrus.WithField("worker", id).Debug("containerd: worker finished") }() + logrus.WithField("worker", id).Debug("containerd: starting worker") for job := range s.jobs { switch j := job.(type) { case *CreateJob: + start := time.Now() container, err := s.runtime.Create(j.ID, j.BundlePath) if err != nil { j.Err <- err @@ -105,6 +115,7 @@ func (s *Supervisor) worker(id int) { Container: container, }) j.Err <- nil + containerStartTimer.UpdateSince(start) } } }