mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f337a8d21d
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
32 lines
676 B
Go
32 lines
676 B
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
|
|
metrics "github.com/docker/go-metrics"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func startMetricsServer(addr string) error {
|
|
if addr == "" {
|
|
return nil
|
|
}
|
|
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() {
|
|
logrus.Infof("metrics API listening on %s", l.Addr())
|
|
if err := http.Serve(l, mux); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
|
|
logrus.WithError(err).Error("error serving metrics API")
|
|
}
|
|
}()
|
|
return nil
|
|
}
|