From 3c0e47e6fd4d49a8ba50aa20a5a2994fd07be3ce Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 15 Mar 2021 16:11:40 +0300 Subject: [PATCH] [#426] cmd/neofs-node: Add metrics collector in node Disabled by default. Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 10 ++++++++++ cmd/neofs-node/main.go | 2 ++ cmd/neofs-node/metrics.go | 15 +++++++++++++++ cmd/neofs-node/object.go | 9 +++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 cmd/neofs-node/metrics.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index bef394dac..8dfd2a3e6 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -58,6 +58,10 @@ const ( cfgProfilerAddr = "pprof.address" cfgProfilerTTL = "pprof.shutdown_ttl" + // metrics keys + cfgMetricsEnable = "metrics.enabled" + cfgMetricsAddr = "metrics.address" + // config keys for cfgNodeInfo cfgNodeKey = "node.key" cfgBootstrapAddress = "node.address" @@ -180,6 +184,8 @@ type cfg struct { profiler profiler.Profiler + metrics profiler.Metrics + workers []worker respSvc *response.Service @@ -414,6 +420,9 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgProfilerAddr, ":6060") v.SetDefault(cfgProfilerTTL, "30s") + v.SetDefault(cfgMetricsEnable, false) + v.SetDefault(cfgMetricsAddr, ":9090") + v.SetDefault(cfgGCQueueSize, 1000) v.SetDefault(cfgGCQueueTick, "5s") v.SetDefault(cfgGCTimeout, "5s") @@ -448,6 +457,7 @@ func initLocalStorage(c *cfg) { ls := engine.New( engine.WithLogger(c.log), + engine.WithMetrics(c.viper.GetBool(cfgMetricsEnable)), ) for _, opts := range c.cfgObject.cfgLocalStorage.shardOpts { diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 249193ac9..2cfc43e14 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -48,6 +48,7 @@ func initApp(c *cfg) { initSessionService(c) initObjectService(c) initProfiler(c) + initMetrics(c) initControlService(c) fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open()) @@ -61,6 +62,7 @@ func bootUp(c *cfg) { serveGRPC(c) bootstrapNode(c) startWorkers(c) + serveMetrics(c) } func wait(c *cfg) { diff --git a/cmd/neofs-node/metrics.go b/cmd/neofs-node/metrics.go new file mode 100644 index 000000000..b1756779b --- /dev/null +++ b/cmd/neofs-node/metrics.go @@ -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) + } +} diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 7805e2f5e..76b25388b 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -299,7 +299,7 @@ func initObjectService(c *cfg) { ) // build service pipeline - // grpc | acl | signature | response | split + // grpc | | acl | signature | response | split splitSvc := objectService.NewTransportSplitter( c.cfgGRPC.maxChunkSize, @@ -344,8 +344,13 @@ func initObjectService(c *cfg) { acl.WithNetmapState(c.cfgNetmap.state), ) + var firstSvc objectService.ServiceServer = aclSvc + if c.viper.GetBool(cfgMetricsEnable) { + firstSvc = objectService.NewMetricCollector(aclSvc) + } + objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server, - objectTransportGRPC.New(aclSvc), + objectTransportGRPC.New(firstSvc), ) }