[#426] cmd/neofs-node: Add metrics collector in node

Disabled by default.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-15 16:11:40 +03:00 committed by Leonard Lyubich
parent 534ce03421
commit 3c0e47e6fd
4 changed files with 34 additions and 2 deletions

View file

@ -58,6 +58,10 @@ const (
cfgProfilerAddr = "pprof.address" cfgProfilerAddr = "pprof.address"
cfgProfilerTTL = "pprof.shutdown_ttl" cfgProfilerTTL = "pprof.shutdown_ttl"
// metrics keys
cfgMetricsEnable = "metrics.enabled"
cfgMetricsAddr = "metrics.address"
// config keys for cfgNodeInfo // config keys for cfgNodeInfo
cfgNodeKey = "node.key" cfgNodeKey = "node.key"
cfgBootstrapAddress = "node.address" cfgBootstrapAddress = "node.address"
@ -180,6 +184,8 @@ type cfg struct {
profiler profiler.Profiler profiler profiler.Profiler
metrics profiler.Metrics
workers []worker workers []worker
respSvc *response.Service respSvc *response.Service
@ -414,6 +420,9 @@ func defaultConfiguration(v *viper.Viper) {
v.SetDefault(cfgProfilerAddr, ":6060") v.SetDefault(cfgProfilerAddr, ":6060")
v.SetDefault(cfgProfilerTTL, "30s") v.SetDefault(cfgProfilerTTL, "30s")
v.SetDefault(cfgMetricsEnable, false)
v.SetDefault(cfgMetricsAddr, ":9090")
v.SetDefault(cfgGCQueueSize, 1000) v.SetDefault(cfgGCQueueSize, 1000)
v.SetDefault(cfgGCQueueTick, "5s") v.SetDefault(cfgGCQueueTick, "5s")
v.SetDefault(cfgGCTimeout, "5s") v.SetDefault(cfgGCTimeout, "5s")
@ -448,6 +457,7 @@ func initLocalStorage(c *cfg) {
ls := engine.New( ls := engine.New(
engine.WithLogger(c.log), engine.WithLogger(c.log),
engine.WithMetrics(c.viper.GetBool(cfgMetricsEnable)),
) )
for _, opts := range c.cfgObject.cfgLocalStorage.shardOpts { for _, opts := range c.cfgObject.cfgLocalStorage.shardOpts {

View file

@ -48,6 +48,7 @@ func initApp(c *cfg) {
initSessionService(c) initSessionService(c)
initObjectService(c) initObjectService(c)
initProfiler(c) initProfiler(c)
initMetrics(c)
initControlService(c) initControlService(c)
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open()) fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
@ -61,6 +62,7 @@ func bootUp(c *cfg) {
serveGRPC(c) serveGRPC(c)
bootstrapNode(c) bootstrapNode(c)
startWorkers(c) startWorkers(c)
serveMetrics(c)
} }
func wait(c *cfg) { func wait(c *cfg) {

15
cmd/neofs-node/metrics.go Normal file
View file

@ -0,0 +1,15 @@
package main
import (
"github.com/nspcc-dev/neofs-node/pkg/util/profiler"
)
func initMetrics(c *cfg) {
c.metrics = profiler.NewMetrics(c.log, c.viper)
}
func serveMetrics(c *cfg) {
if c.metrics != nil {
c.metrics.Start(c.ctx)
}
}

View file

@ -299,7 +299,7 @@ func initObjectService(c *cfg) {
) )
// build service pipeline // build service pipeline
// grpc | acl | signature | response | split // grpc | <metrics> | acl | signature | response | split
splitSvc := objectService.NewTransportSplitter( splitSvc := objectService.NewTransportSplitter(
c.cfgGRPC.maxChunkSize, c.cfgGRPC.maxChunkSize,
@ -344,8 +344,13 @@ func initObjectService(c *cfg) {
acl.WithNetmapState(c.cfgNetmap.state), acl.WithNetmapState(c.cfgNetmap.state),
) )
var firstSvc objectService.ServiceServer = aclSvc
if c.viper.GetBool(cfgMetricsEnable) {
firstSvc = objectService.NewMetricCollector(aclSvc)
}
objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server, objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server,
objectTransportGRPC.New(aclSvc), objectTransportGRPC.New(firstSvc),
) )
} }