From 581a9901c97723801f84c923136b2589d35230d5 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 19 Jul 2022 18:16:42 +0300 Subject: [PATCH] [#1614] metrics: Add health metrics Also, rename metrics structure since it collects not only storage metrics now. Signed-off-by: Pavel Karpy --- cmd/neofs-node/config.go | 4 ++-- cmd/neofs-node/netmap.go | 2 +- pkg/metrics/metrics.go | 13 +++++++++---- pkg/metrics/state.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 pkg/metrics/state.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 36b166a7c..a738f1f22 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -105,7 +105,7 @@ type cfg struct { cfgNotifications cfgNotifications - metricsCollector *metrics.StorageMetrics + metricsCollector *metrics.NodeMetrics workers []worker @@ -326,7 +326,7 @@ func initCfg(path string) *cfg { user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey) if metricsconfig.Enabled(c.appCfg) { - c.metricsCollector = metrics.NewStorageMetrics() + c.metricsCollector = metrics.NewNodeMetrics() netState.metrics = c.metricsCollector } diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 6174e29cf..86dc397c7 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -31,7 +31,7 @@ type networkState struct { nodeInfo atomic.Value // *netmapSDK.NodeInfo - metrics *metrics.StorageMetrics + metrics *metrics.NodeMetrics } func newNetworkState() *networkState { diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index e21fce099..9e87f0ac1 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -4,19 +4,23 @@ import "github.com/prometheus/client_golang/prometheus" const namespace = "neofs_node" -type StorageMetrics struct { +type NodeMetrics struct { objectServiceMetrics engineMetrics + stateMetrics epoch prometheus.Gauge } -func NewStorageMetrics() *StorageMetrics { +func NewNodeMetrics() *NodeMetrics { objectService := newObjectServiceMetrics() objectService.register() engine := newEngineMetrics() engine.register() + state := newStateMetrics() + state.register() + epoch := prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: innerRingSubsystem, @@ -25,14 +29,15 @@ func NewStorageMetrics() *StorageMetrics { }) prometheus.MustRegister(epoch) - return &StorageMetrics{ + return &NodeMetrics{ objectServiceMetrics: objectService, engineMetrics: engine, + stateMetrics: state, epoch: epoch, } } // SetEpoch updates epoch metric. -func (m *StorageMetrics) SetEpoch(epoch uint64) { +func (m *NodeMetrics) SetEpoch(epoch uint64) { m.epoch.Set(float64(epoch)) } diff --git a/pkg/metrics/state.go b/pkg/metrics/state.go new file mode 100644 index 000000000..94e28af38 --- /dev/null +++ b/pkg/metrics/state.go @@ -0,0 +1,28 @@ +package metrics + +import "github.com/prometheus/client_golang/prometheus" + +const stateSubsystem = "state" + +type stateMetrics struct { + healthCheck prometheus.Gauge +} + +func newStateMetrics() stateMetrics { + return stateMetrics{ + healthCheck: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: stateSubsystem, + Name: "health", + Help: "Current Node state", + }), + } +} + +func (m stateMetrics) register() { + prometheus.MustRegister(m.healthCheck) +} + +func (m stateMetrics) SetHealth(s int32) { + m.healthCheck.Set(float64(s)) +}