Remove go-metrics

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-09-20 10:14:53 -07:00
parent 0645faf690
commit 058eea362a
12 changed files with 1 additions and 159 deletions

View file

@ -2,8 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"log"
"net"
"os" "os"
"os/signal" "os/signal"
"runtime" "runtime"
@ -18,14 +16,12 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/cyberdelia/go-metrics-graphite"
"github.com/docker/containerd" "github.com/docker/containerd"
"github.com/docker/containerd/api/grpc/server" "github.com/docker/containerd/api/grpc/server"
"github.com/docker/containerd/api/grpc/types" "github.com/docker/containerd/api/grpc/types"
"github.com/docker/containerd/api/http/pprof" "github.com/docker/containerd/api/http/pprof"
"github.com/docker/containerd/supervisor" "github.com/docker/containerd/supervisor"
"github.com/docker/docker/pkg/listeners" "github.com/docker/docker/pkg/listeners"
"github.com/rcrowley/go-metrics"
) )
const ( const (
@ -45,11 +41,6 @@ var daemonFlags = []cli.Flag{
Value: defaultStateDir, Value: defaultStateDir,
Usage: "runtime state directory", Usage: "runtime state directory",
}, },
cli.DurationFlag{
Name: "metrics-interval",
Value: 5 * time.Minute,
Usage: "interval for flushing metrics to the store",
},
cli.StringFlag{ cli.StringFlag{
Name: "listen,l", Name: "listen,l",
Value: defaultGRPCEndpoint, Value: defaultGRPCEndpoint,
@ -84,10 +75,6 @@ var daemonFlags = []cli.Flag{
Value: 500, Value: 500,
Usage: "number of past events to keep in the event log", Usage: "number of past events to keep in the event log",
}, },
cli.StringFlag{
Name: "graphite-address",
Usage: "Address of graphite server",
},
} }
// DumpStacks dumps the runtime stack. // DumpStacks dumps the runtime stack.
@ -131,11 +118,6 @@ func main() {
setupDumpStacksTrap() setupDumpStacksTrap()
if context.GlobalBool("debug") { if context.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
if context.GlobalDuration("metrics-interval") > 0 {
if err := debugMetrics(context.GlobalDuration("metrics-interval"), context.GlobalString("graphite-address")); err != nil {
return err
}
}
} }
if p := context.GlobalString("pprof-address"); len(p) > 0 { if p := context.GlobalString("pprof-address"); len(p) > 0 {
pprof.Enable(p) pprof.Enable(p)
@ -248,23 +230,3 @@ func checkLimits() error {
} }
return nil return nil
} }
func debugMetrics(interval time.Duration, graphiteAddr string) error {
for name, m := range supervisor.Metrics() {
if err := metrics.DefaultRegistry.Register(name, m); err != nil {
return err
}
}
processMetrics()
if graphiteAddr != "" {
addr, err := net.ResolveTCPAddr("tcp", graphiteAddr)
if err != nil {
return err
}
go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)
} else {
l := log.New(os.Stdout, "[containerd] ", log.LstdFlags)
go metrics.Log(metrics.DefaultRegistry, interval, l)
}
return nil
}

View file

@ -1,45 +0,0 @@
package main
import (
"os"
"runtime"
"time"
"github.com/Sirupsen/logrus"
"github.com/cloudfoundry/gosigar"
"github.com/docker/containerd/osutils"
"github.com/rcrowley/go-metrics"
)
func processMetrics() {
var (
g = metrics.NewGauge()
fg = metrics.NewGauge()
memg = metrics.NewGauge()
)
metrics.DefaultRegistry.Register("goroutines", g)
metrics.DefaultRegistry.Register("fds", fg)
metrics.DefaultRegistry.Register("memory-used", memg)
collect := func() {
// update number of goroutines
g.Update(int64(runtime.NumGoroutine()))
// collect the number of open fds
fds, err := osutils.GetOpenFds(os.Getpid())
if err != nil {
logrus.WithField("error", err).Error("containerd: get open fd count")
}
fg.Update(int64(fds))
// get the memory used
m := sigar.ProcMem{}
if err := m.Get(os.Getpid()); err != nil {
logrus.WithField("error", err).Error("containerd: get pid memory information")
}
memg.Update(int64(m.Size))
}
go func() {
collect()
for range time.Tick(30 * time.Second) {
collect()
}
}()
}

View file

@ -1,4 +0,0 @@
package main
func processMetrics() {
}

View file

@ -21,7 +21,6 @@ type AddProcessTask struct {
} }
func (s *Supervisor) addProcess(t *AddProcessTask) error { func (s *Supervisor) addProcess(t *AddProcessTask) error {
start := time.Now()
ci, ok := s.containers[t.ID] ci, ok := s.containers[t.ID]
if !ok { if !ok {
return ErrContainerNotFound return ErrContainerNotFound
@ -33,7 +32,6 @@ func (s *Supervisor) addProcess(t *AddProcessTask) error {
if err := s.monitorProcess(process); err != nil { if err := s.monitorProcess(process); err != nil {
return err return err
} }
ExecProcessTimer.UpdateSince(start)
t.StartResponse <- StartResponse{} t.StartResponse <- StartResponse{}
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Timestamp: time.Now(), Timestamp: time.Now(),

View file

@ -2,7 +2,6 @@ package supervisor
import ( import (
"path/filepath" "path/filepath"
"time"
"github.com/docker/containerd/runtime" "github.com/docker/containerd/runtime"
) )
@ -25,7 +24,6 @@ type StartTask struct {
} }
func (s *Supervisor) start(t *StartTask) error { func (s *Supervisor) start(t *StartTask) error {
start := time.Now()
rt := s.runtime rt := s.runtime
rtArgs := s.runtimeArgs rtArgs := s.runtimeArgs
if t.Runtime != "" { if t.Runtime != "" {
@ -49,7 +47,6 @@ func (s *Supervisor) start(t *StartTask) error {
s.containers[t.ID] = &containerInfo{ s.containers[t.ID] = &containerInfo{
container: container, container: container,
} }
ContainersCounter.Inc(1)
task := &startTask{ task := &startTask{
Err: t.ErrorCh(), Err: t.ErrorCh(),
Container: container, Container: container,
@ -63,6 +60,5 @@ func (s *Supervisor) start(t *StartTask) error {
} }
s.startTasks <- task s.startTasks <- task
ContainerCreateTimer.UpdateSince(start)
return errDeferredResponse return errDeferredResponse
} }

View file

@ -19,7 +19,6 @@ type DeleteTask struct {
func (s *Supervisor) delete(t *DeleteTask) error { func (s *Supervisor) delete(t *DeleteTask) error {
if i, ok := s.containers[t.ID]; ok { if i, ok := s.containers[t.ID]; ok {
start := time.Now()
if err := s.deleteContainer(i.container); err != nil { if err := s.deleteContainer(i.container); err != nil {
logrus.WithField("error", err).Error("containerd: deleting container") logrus.WithField("error", err).Error("containerd: deleting container")
} }
@ -35,8 +34,6 @@ func (s *Supervisor) delete(t *DeleteTask) error {
PID: t.PID, PID: t.PID,
}) })
} }
ContainersCounter.Dec(1)
ContainerDeleteTimer.UpdateSince(start)
} }
return nil return nil
} }

View file

@ -14,7 +14,6 @@ type ExitTask struct {
} }
func (s *Supervisor) exit(t *ExitTask) error { func (s *Supervisor) exit(t *ExitTask) error {
start := time.Now()
proc := t.Process proc := t.Process
status, err := proc.ExitStatus() status, err := proc.ExitStatus()
if err != nil { if err != nil {
@ -52,9 +51,6 @@ func (s *Supervisor) exit(t *ExitTask) error {
Process: proc, Process: proc,
} }
s.delete(ne) s.delete(ne)
ExitProcessTimer.UpdateSince(start)
return nil return nil
} }

View file

@ -1,42 +0,0 @@
package supervisor
import "github.com/rcrowley/go-metrics"
var (
// ContainerCreateTimer holds the metrics timer associated with container creation
ContainerCreateTimer = metrics.NewTimer()
// ContainerDeleteTimer holds the metrics timer associated with container deletion
ContainerDeleteTimer = metrics.NewTimer()
// ContainerStartTimer holds the metrics timer associated with container start duration
ContainerStartTimer = metrics.NewTimer()
// ContainerStatsTimer holds the metrics timer associated with container stats generation
ContainerStatsTimer = metrics.NewTimer()
// ContainersCounter keeps track of the number of active containers
ContainersCounter = metrics.NewCounter()
// EventSubscriberCounter keeps track of the number of active event subscribers
EventSubscriberCounter = metrics.NewCounter()
// TasksCounter keeps track of the number of active supervisor tasks
TasksCounter = metrics.NewCounter()
// ExecProcessTimer holds the metrics timer associated with container exec
ExecProcessTimer = metrics.NewTimer()
// ExitProcessTimer holds the metrics timer associated with reporting container exit status
ExitProcessTimer = metrics.NewTimer()
// EpollFdCounter keeps trac of how many process are being monitored
EpollFdCounter = metrics.NewCounter()
)
// Metrics return the list of all available metrics
func Metrics() map[string]interface{} {
return map[string]interface{}{
"container-create-time": ContainerCreateTimer,
"container-delete-time": ContainerDeleteTimer,
"container-start-time": ContainerStartTimer,
"container-stats-time": ContainerStatsTimer,
"containers": ContainersCounter,
"event-subscribers": EventSubscriberCounter,
"tasks": TasksCounter,
"exec-process-time": ExecProcessTimer,
"exit-process-time": ExitProcessTimer,
"epoll-fds": EpollFdCounter,
}
}

View file

@ -56,7 +56,6 @@ func (m *Monitor) Monitor(p runtime.Process) error {
if err := archutils.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil { if err := archutils.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil {
return err return err
} }
EpollFdCounter.Inc(1)
m.receivers[fd] = p m.receivers[fd] = p
return nil return nil
} }
@ -77,7 +76,6 @@ func (m *Monitor) MonitorOOM(c runtime.Container) error {
if err := archutils.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil { if err := archutils.EpollCtl(m.epollFd, syscall.EPOLL_CTL_ADD, fd, &event); err != nil {
return err return err
} }
EpollFdCounter.Inc(1)
m.receivers[fd] = o m.receivers[fd] = o
return nil return nil
} }
@ -115,7 +113,6 @@ func (m *Monitor) start() {
if err := t.Close(); err != nil { if err := t.Close(); err != nil {
logrus.WithField("error", err).Error("containerd: close process IO") logrus.WithField("error", err).Error("containerd: close process IO")
} }
EpollFdCounter.Dec(1)
m.exits <- t m.exits <- t
} }
case runtime.OOM: case runtime.OOM:
@ -125,7 +122,6 @@ func (m *Monitor) start() {
delete(m.receivers, fd) delete(m.receivers, fd)
// epoll will remove the fd from its set after it has been closed // epoll will remove the fd from its set after it has been closed
t.Close() t.Close()
EpollFdCounter.Dec(1)
} else { } else {
m.ooms <- t.ContainerID() m.ooms <- t.ContainerID()
} }

View file

@ -1,10 +1,6 @@
package supervisor package supervisor
import ( import "github.com/docker/containerd/runtime"
"time"
"github.com/docker/containerd/runtime"
)
// StatsTask holds needed parameters to retrieve a container statistics // StatsTask holds needed parameters to retrieve a container statistics
type StatsTask struct { type StatsTask struct {
@ -14,7 +10,6 @@ type StatsTask struct {
} }
func (s *Supervisor) stats(t *StatsTask) error { func (s *Supervisor) stats(t *StatsTask) error {
start := time.Now()
i, ok := s.containers[t.ID] i, ok := s.containers[t.ID]
if !ok { if !ok {
return ErrContainerNotFound return ErrContainerNotFound
@ -28,7 +23,6 @@ func (s *Supervisor) stats(t *StatsTask) error {
} }
t.ErrorCh() <- nil t.ErrorCh() <- nil
t.Stat <- s t.Stat <- s
ContainerStatsTimer.UpdateSince(start)
}() }()
return errDeferredResponse return errDeferredResponse
} }

View file

@ -214,7 +214,6 @@ func (s *Supervisor) Events(from time.Time, storedOnly bool, id string) chan Eve
if storedOnly { if storedOnly {
close(c) close(c)
} else { } else {
EventSubscriberCounter.Inc(1)
s.subscribers[c] = struct{}{} s.subscribers[c] = struct{}{}
} }
return c return c
@ -227,7 +226,6 @@ func (s *Supervisor) Unsubscribe(sub chan Event) {
if _, ok := s.subscribers[sub]; ok { if _, ok := s.subscribers[sub]; ok {
delete(s.subscribers, sub) delete(s.subscribers, sub)
close(sub) close(sub)
EventSubscriberCounter.Dec(1)
} }
} }
@ -276,7 +274,6 @@ func (s *Supervisor) Machine() Machine {
// SendTask sends the provided event the the supervisors main event loop // SendTask sends the provided event the the supervisors main event loop
func (s *Supervisor) SendTask(evt Task) { func (s *Supervisor) SendTask(evt Task) {
TasksCounter.Inc(1)
s.tasks <- evt s.tasks <- evt
} }
@ -321,7 +318,6 @@ func (s *Supervisor) restore() error {
return err return err
} }
ContainersCounter.Inc(1)
s.containers[id] = &containerInfo{ s.containers[id] = &containerInfo{
container: container, container: container,
} }

View file

@ -40,7 +40,6 @@ type worker struct {
func (w *worker) Start() { func (w *worker) Start() {
defer w.wg.Done() defer w.wg.Done()
for t := range w.s.startTasks { for t := range w.s.startTasks {
started := time.Now()
process, err := t.Container.Start(t.CheckpointPath, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr)) process, err := t.Container.Start(t.CheckpointPath, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr))
if err != nil { if err != nil {
logrus.WithFields(logrus.Fields{ logrus.WithFields(logrus.Fields{
@ -87,7 +86,6 @@ func (w *worker) Start() {
continue continue
} }
} }
ContainerStartTimer.UpdateSince(started)
t.Err <- nil t.Err <- nil
t.StartResponse <- StartResponse{ t.StartResponse <- StartResponse{
Container: t.Container, Container: t.Container,