[#1658] metrics: Add object type label to the counters

It will allow to use labeled object counters, e.g.: "phy" for all
the physically stored objects, "logic" for only available objects. Also, it
will allow to add typed (regular, TS, SG, LOCK) counters if needed.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-09-09 12:47:07 +03:00 committed by LeL
parent a789159e5b
commit 175e2b9fa0

View file

@ -33,7 +33,10 @@ type (
} }
) )
const shardIDLabelKey = "shard" const (
shardIDLabelKey = "shard"
counterTypeLabelKey = "type"
)
func newObjectServiceMetrics() objectServiceMetrics { func newObjectServiceMetrics() objectServiceMetrics {
var ( // Request counter metrics. var ( // Request counter metrics.
@ -159,7 +162,7 @@ func newObjectServiceMetrics() objectServiceMetrics {
Name: "counter", Name: "counter",
Help: "Objects counters per shards", Help: "Objects counters per shards",
}, },
[]string{shardIDLabelKey}, []string{shardIDLabelKey, counterTypeLabelKey},
) )
) )
@ -271,10 +274,20 @@ func (m objectServiceMetrics) AddGetPayload(ln int) {
m.getPayload.Add(float64(ln)) m.getPayload.Add(float64(ln))
} }
func (m objectServiceMetrics) AddToObjectCounter(shardID string, delta int) { func (m objectServiceMetrics) AddToObjectCounter(shardID, objectType string, delta int) {
m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(delta)) m.shardMetrics.With(
prometheus.Labels{
shardIDLabelKey: shardID,
counterTypeLabelKey: objectType,
},
).Add(float64(delta))
} }
func (m objectServiceMetrics) SetObjectCounter(shardID string, v uint64) { func (m objectServiceMetrics) SetObjectCounter(shardID, objectType string, v uint64) {
m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(float64(v)) m.shardMetrics.With(
prometheus.Labels{
shardIDLabelKey: shardID,
counterTypeLabelKey: objectType,
},
).Set(float64(v))
} }