2016-07-20 23:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
|
2018-05-19 11:38:54 +00:00
|
|
|
"github.com/docker/go-metrics"
|
2017-07-26 21:42:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-07-20 23:11:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|