mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
88c554f950
Fix TODO: move into startMetricsServer() Fix errors.Wrap return nil when passed err is nil Co-Authored-By: Sebastiaan van Stijn <thaJeztah@users.noreply.github.com> Signed-off-by: HuanHuan Ye <logindaveye@gmail.com>
36 lines
679 B
Go
36 lines
679 B
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
|
|
"github.com/docker/go-metrics"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (cli *DaemonCli) startMetricsServer(addr string) error {
|
|
if addr == "" {
|
|
return nil
|
|
}
|
|
|
|
if !cli.d.HasExperimental() {
|
|
return errors.New("metrics-addr is only supported when experimental is enabled")
|
|
}
|
|
|
|
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
|
|
}
|