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
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") {

View file

@ -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)
}
}
}