2021-03-15 13:11:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-05-11 22:59:05 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
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-05-11 22:59:05 +00:00
|
|
|
addr := c.viper.GetString(cfgMetricsAddr)
|
|
|
|
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(
|
|
|
|
c.viper.GetDuration(cfgMetricsShutdownTimeout),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|