2021-03-15 13:11:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-05-11 22:59:05 +00:00
|
|
|
"context"
|
|
|
|
|
2021-06-01 11:24:57 +00:00
|
|
|
metricsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/metrics"
|
2021-05-11 22:59:05 +00:00
|
|
|
httputil "github.com/nspcc-dev/neofs-node/pkg/util/http"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"go.uber.org/zap"
|
2021-03-15 13:11:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func initMetrics(c *cfg) {
|
2021-06-01 11:24:57 +00:00
|
|
|
addr := metricsconfig.Address(c.appCfg)
|
2021-05-11 22:59:05 +00:00
|
|
|
if addr == "" {
|
|
|
|
return
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
2021-03-15 13:11:40 +00:00
|
|
|
|
2021-05-11 22:59:05 +00:00
|
|
|
var prm httputil.Prm
|
|
|
|
|
|
|
|
prm.Address = addr
|
|
|
|
prm.Handler = promhttp.Handler()
|
|
|
|
|
|
|
|
srv := httputil.New(prm,
|
|
|
|
httputil.WithShutdownTimeout(
|
2021-06-01 11:24:57 +00:00
|
|
|
metricsconfig.ShutdownTimeout(c.appCfg),
|
2021-05-11 22:59:05 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
c.workers = append(c.workers, newWorkerFromFunc(func(context.Context) {
|
|
|
|
fatalOnErr(srv.Serve())
|
|
|
|
}))
|
|
|
|
|
|
|
|
c.closers = append(c.closers, func() {
|
|
|
|
err := srv.Shutdown()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("could not shutdown metrics server",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
2021-03-15 13:11:40 +00:00
|
|
|
}
|