From 067ab44e0b8411f22d2c5f7cfbc8d43058a31f7e Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 19 Aug 2022 19:41:29 +0300 Subject: [PATCH] [#1658] metrics: Add object counter metric Signed-off-by: Pavel Karpy --- pkg/metrics/object.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/metrics/object.go b/pkg/metrics/object.go index c447f5d2e..e5c0292c8 100644 --- a/pkg/metrics/object.go +++ b/pkg/metrics/object.go @@ -28,9 +28,13 @@ type ( putPayload prometheus.Counter getPayload prometheus.Counter + + shardMetrics *prometheus.GaugeVec } ) +const shardIDLabelKey = "shard" + func newObjectServiceMetrics() objectServiceMetrics { var ( // Request counter metrics. getCounter = prometheus.NewCounter(prometheus.CounterOpts{ @@ -148,6 +152,15 @@ func newObjectServiceMetrics() objectServiceMetrics { Name: "get_payload", Help: "Accumulated payload size at object get method", }) + + shardsMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: "counter", + Help: "Objects counters per shards", + }, + []string{shardIDLabelKey}, + ) ) return objectServiceMetrics{ @@ -167,6 +180,7 @@ func newObjectServiceMetrics() objectServiceMetrics { rangeHashDuration: rangeHashDuration, putPayload: putPayload, getPayload: getPayload, + shardMetrics: shardsMetrics, } } @@ -189,6 +203,8 @@ func (m objectServiceMetrics) register() { prometheus.MustRegister(m.putPayload) prometheus.MustRegister(m.getPayload) + + prometheus.MustRegister(m.shardMetrics) } func (m objectServiceMetrics) IncGetReqCounter() { @@ -254,3 +270,7 @@ func (m objectServiceMetrics) AddPutPayload(ln int) { func (m objectServiceMetrics) AddGetPayload(ln int) { m.getPayload.Add(float64(ln)) } + +func (m objectServiceMetrics) AddToObjectCounter(shardID string, delta int) { + m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(delta)) +}