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) {
|
2022-07-13 09:17:37 +00:00
|
|
|
if !metricsconfig.Enabled(c.appCfg) {
|
2022-07-13 09:26:40 +00:00
|
|
|
c.log.Info("prometheus is disabled")
|
2021-05-11 22:59:05 +00:00
|
|
|
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
|
|
|
|
|
2022-07-13 09:17:37 +00:00
|
|
|
prm.Address = metricsconfig.Address(c.appCfg)
|
2021-05-11 22:59:05 +00:00
|
|
|
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) {
|
2022-05-25 16:18:36 +00:00
|
|
|
runAndLog(c, "metrics", false, func(c *cfg) {
|
|
|
|
fatalOnErr(srv.Serve())
|
|
|
|
})
|
2021-05-11 22:59:05 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
c.closers = append(c.closers, func() {
|
2021-08-04 14:44:37 +00:00
|
|
|
c.log.Debug("shutting down metrics service")
|
|
|
|
|
2021-05-11 22:59:05 +00:00
|
|
|
err := srv.Shutdown()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("could not shutdown metrics server",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
2021-08-04 14:44:37 +00:00
|
|
|
|
|
|
|
c.log.Debug("metrics service has been stopped")
|
2021-05-11 22:59:05 +00:00
|
|
|
})
|
2021-03-15 13:11:40 +00:00
|
|
|
}
|