[#1658] metrics: Add object counter metric

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-19 19:41:29 +03:00 committed by fyrchik
parent 626766db08
commit 067ab44e0b

View file

@ -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))
}