forked from TrueCloudLab/frostfs-node
[#1614] metrics: Add health metrics
Also, rename metrics structure since it collects not only storage metrics now. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
2455b72844
commit
581a9901c9
4 changed files with 40 additions and 7 deletions
|
@ -105,7 +105,7 @@ type cfg struct {
|
||||||
|
|
||||||
cfgNotifications cfgNotifications
|
cfgNotifications cfgNotifications
|
||||||
|
|
||||||
metricsCollector *metrics.StorageMetrics
|
metricsCollector *metrics.NodeMetrics
|
||||||
|
|
||||||
workers []worker
|
workers []worker
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ func initCfg(path string) *cfg {
|
||||||
user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey)
|
user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey)
|
||||||
|
|
||||||
if metricsconfig.Enabled(c.appCfg) {
|
if metricsconfig.Enabled(c.appCfg) {
|
||||||
c.metricsCollector = metrics.NewStorageMetrics()
|
c.metricsCollector = metrics.NewNodeMetrics()
|
||||||
netState.metrics = c.metricsCollector
|
netState.metrics = c.metricsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ type networkState struct {
|
||||||
|
|
||||||
nodeInfo atomic.Value // *netmapSDK.NodeInfo
|
nodeInfo atomic.Value // *netmapSDK.NodeInfo
|
||||||
|
|
||||||
metrics *metrics.StorageMetrics
|
metrics *metrics.NodeMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNetworkState() *networkState {
|
func newNetworkState() *networkState {
|
||||||
|
|
|
@ -4,19 +4,23 @@ import "github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
const namespace = "neofs_node"
|
const namespace = "neofs_node"
|
||||||
|
|
||||||
type StorageMetrics struct {
|
type NodeMetrics struct {
|
||||||
objectServiceMetrics
|
objectServiceMetrics
|
||||||
engineMetrics
|
engineMetrics
|
||||||
|
stateMetrics
|
||||||
epoch prometheus.Gauge
|
epoch prometheus.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStorageMetrics() *StorageMetrics {
|
func NewNodeMetrics() *NodeMetrics {
|
||||||
objectService := newObjectServiceMetrics()
|
objectService := newObjectServiceMetrics()
|
||||||
objectService.register()
|
objectService.register()
|
||||||
|
|
||||||
engine := newEngineMetrics()
|
engine := newEngineMetrics()
|
||||||
engine.register()
|
engine.register()
|
||||||
|
|
||||||
|
state := newStateMetrics()
|
||||||
|
state.register()
|
||||||
|
|
||||||
epoch := prometheus.NewGauge(prometheus.GaugeOpts{
|
epoch := prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: innerRingSubsystem,
|
Subsystem: innerRingSubsystem,
|
||||||
|
@ -25,14 +29,15 @@ func NewStorageMetrics() *StorageMetrics {
|
||||||
})
|
})
|
||||||
prometheus.MustRegister(epoch)
|
prometheus.MustRegister(epoch)
|
||||||
|
|
||||||
return &StorageMetrics{
|
return &NodeMetrics{
|
||||||
objectServiceMetrics: objectService,
|
objectServiceMetrics: objectService,
|
||||||
engineMetrics: engine,
|
engineMetrics: engine,
|
||||||
|
stateMetrics: state,
|
||||||
epoch: epoch,
|
epoch: epoch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEpoch updates epoch metric.
|
// SetEpoch updates epoch metric.
|
||||||
func (m *StorageMetrics) SetEpoch(epoch uint64) {
|
func (m *NodeMetrics) SetEpoch(epoch uint64) {
|
||||||
m.epoch.Set(float64(epoch))
|
m.epoch.Set(float64(epoch))
|
||||||
}
|
}
|
||||||
|
|
28
pkg/metrics/state.go
Normal file
28
pkg/metrics/state.go
Normal file
|
@ -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))
|
||||||
|
}
|
Loading…
Reference in a new issue