Add basic prometheus support
This adds a metrics packages that creates additional metrics. Add the metrics endpoint to the docker api server under `/metrics`. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Add metrics to daemon package Signed-off-by: Michael Crosby <crosbymichael@gmail.com> api: use standard way for metrics route Also add "type" query parameter Signed-off-by: Alexander Morozov <lk4d4@docker.com> Convert timers to ms Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Upstream-commit: 3343d234f3b131d4be1d4ca84385e184633a79bd Component: engine
This commit is contained in:
@ -248,6 +248,15 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
|
||||
return fmt.Errorf("Error starting daemon: %v", err)
|
||||
}
|
||||
|
||||
if cli.Config.MetricsAddress != "" {
|
||||
if !d.HasExperimental() {
|
||||
return fmt.Errorf("metrics-addr is only supported when experimental is enabled")
|
||||
}
|
||||
if err := startMetricsServer(cli.Config.MetricsAddress); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
name, _ := os.Hostname()
|
||||
|
||||
c, err := cluster.New(cluster.Config{
|
||||
|
||||
27
components/engine/cmd/dockerd/metrics.go
Normal file
27
components/engine/cmd/dockerd/metrics.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
metrics "github.com/docker/go-metrics"
|
||||
)
|
||||
|
||||
func startMetricsServer(addr string) error {
|
||||
if err := allocateDaemonPort(addr); err != nil {
|
||||
return err
|
||||
}
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/metrics", metrics.Handler())
|
||||
go func() {
|
||||
if err := http.Serve(l, mux); err != nil {
|
||||
logrus.Errorf("serve metrics api: %s", err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user