diff --git a/pkg/local_object_storage/engine/metrics.go b/pkg/local_object_storage/engine/metrics.go index 254a7d6d5d..98aacb77ad 100644 --- a/pkg/local_object_storage/engine/metrics.go +++ b/pkg/local_object_storage/engine/metrics.go @@ -17,6 +17,7 @@ type MetricRegister interface { AddSearchDuration(d time.Duration) AddListObjectsDuration(d time.Duration) + SetObjectCounter(shardID string, v uint64) AddToObjectCounter(shardID string, delta int) } diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index db72fd8be8..d0a7fe0c18 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -22,6 +22,10 @@ type metricsWithID struct { mw MetricRegister } +func (m metricsWithID) SetObjectCounter(v uint64) { + m.mw.SetObjectCounter(m.id, v) +} + func (m metricsWithID) AddToObjectCounter(delta int) { m.mw.AddToObjectCounter(m.id, delta) } diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 7ca5f8a388..76e582dc19 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -120,6 +120,8 @@ func (s *Shard) Init() error { } } + s.updateObjectCounter() + s.gc = &gc{ gcCfg: s.gcCfg, remover: s.removeGarbage, diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index bd54fc940d..0785637cc3 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -47,6 +47,8 @@ type DeletedLockCallback func(context.Context, []oid.Address) // MetricsWriter is an interface that must store shard's metrics. type MetricsWriter interface { + // SetObjectCounter must set object counter. + SetObjectCounter(v uint64) // AddToObjectCounter must update object counter. Negative // parameter must decrease the counter. AddToObjectCounter(delta int) @@ -293,6 +295,21 @@ func (s *Shard) fillInfo() { } } +func (s *Shard) updateObjectCounter() { + if s.cfg.metricsWriter != nil && !s.GetMode().NoMetabase() { + c, err := s.metaBase.ObjectCounter() + if err != nil { + s.log.Warn("meta: object counter read", + zap.Error(err), + ) + + return + } + + s.cfg.metricsWriter.SetObjectCounter(c) + } +} + func (s *Shard) incObjectCounter() { if s.cfg.metricsWriter != nil { s.cfg.metricsWriter.IncObjectCounter() diff --git a/pkg/metrics/object.go b/pkg/metrics/object.go index e5c0292c85..5c4d2396ae 100644 --- a/pkg/metrics/object.go +++ b/pkg/metrics/object.go @@ -274,3 +274,7 @@ func (m objectServiceMetrics) AddGetPayload(ln int) { func (m objectServiceMetrics) AddToObjectCounter(shardID string, delta int) { m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(delta)) } + +func (m objectServiceMetrics) SetObjectCounter(shardID string, v uint64) { + m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(float64(v)) +}