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

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
containerd/containerd

View file

@ -1,14 +1,18 @@
package main package main
import ( import (
"log"
"os" "os"
"os/signal" "os/signal"
"runtime"
"syscall" "syscall"
"time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/crosbymichael/containerd" "github.com/crosbymichael/containerd"
"github.com/opencontainers/runc/libcontainer/utils" "github.com/opencontainers/runc/libcontainer/utils"
"github.com/rcrowley/go-metrics"
) )
var DaemonCommand = cli.Command{ var DaemonCommand = cli.Command{
@ -26,6 +30,17 @@ var DaemonCommand = cli.Command{
}, },
}, },
Action: func(context *cli.Context) { 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 { if err := daemon(context.String("state-dir"), 20, context.Int("buffer-size")); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View file

@ -28,6 +28,7 @@ func main() {
} }
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.BoolFlag{Name: "debug", Usage: "enable debug output in the logs"}, 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 { app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") { if context.GlobalBool("debug") {

View file

@ -3,8 +3,14 @@ package containerd
import ( import (
"os" "os"
"sync" "sync"
"time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/rcrowley/go-metrics"
)
var (
containerStartTimer = metrics.NewTimer()
) )
// NewSupervisor returns an initialized Process supervisor. // 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 { if err := os.MkdirAll(stateDir, 0755); err != nil {
return nil, err return nil, err
} }
// register counters
metrics.DefaultRegistry.Register("container-start-time", containerStartTimer)
runtime, err := NewRuntime(stateDir) runtime, err := NewRuntime(stateDir)
if err != nil { if err != nil {
return nil, err return nil, err
@ -93,9 +101,11 @@ func (s *Supervisor) worker(id int) {
s.workerGroup.Done() s.workerGroup.Done()
logrus.WithField("worker", id).Debug("containerd: worker finished") logrus.WithField("worker", id).Debug("containerd: worker finished")
}() }()
logrus.WithField("worker", id).Debug("containerd: starting worker")
for job := range s.jobs { for job := range s.jobs {
switch j := job.(type) { switch j := job.(type) {
case *CreateJob: case *CreateJob:
start := time.Now()
container, err := s.runtime.Create(j.ID, j.BundlePath) container, err := s.runtime.Create(j.ID, j.BundlePath)
if err != nil { if err != nil {
j.Err <- err j.Err <- err
@ -105,6 +115,7 @@ func (s *Supervisor) worker(id int) {
Container: container, Container: container,
}) })
j.Err <- nil j.Err <- nil
containerStartTimer.UpdateSince(start)
} }
} }
} }