moby/cmd/dockerd/metrics.go
Sebastiaan van Stijn cff4f20c44
migrate to github.com/containerd/log v0.1.0
The github.com/containerd/containerd/log package was moved to a separate
module, which will also be used by upcoming (patch) releases of containerd.

This patch moves our own uses of the package to use the new module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-11 17:52:23 +02:00

38 lines
917 B
Go

package main
import (
"context"
"net"
"net/http"
"strings"
"time"
"github.com/containerd/log"
metrics "github.com/docker/go-metrics"
)
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() {
log.G(context.TODO()).Infof("metrics API listening on %s", l.Addr())
srv := &http.Server{
Handler: mux,
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
}
if err := srv.Serve(l); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
log.G(context.TODO()).WithError(err).Error("error serving metrics API")
}
}()
return nil
}