2021-03-16 08:14:56 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2022-11-29 11:51:19 +00:00
|
|
|
"fmt"
|
2023-04-05 09:43:32 +00:00
|
|
|
"strings"
|
2021-03-16 08:14:56 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
const objectSubsystem = "object"
|
|
|
|
|
|
|
|
type (
|
2022-11-29 11:51:19 +00:00
|
|
|
methodCount struct {
|
2023-04-05 10:39:02 +00:00
|
|
|
success metric[prometheus.Counter]
|
|
|
|
total metric[prometheus.Counter]
|
2022-11-29 11:51:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 08:14:56 +00:00
|
|
|
objectServiceMetrics struct {
|
2022-11-29 11:51:19 +00:00
|
|
|
getCounter methodCount
|
|
|
|
putCounter methodCount
|
|
|
|
headCounter methodCount
|
|
|
|
searchCounter methodCount
|
|
|
|
deleteCounter methodCount
|
|
|
|
rangeCounter methodCount
|
|
|
|
rangeHashCounter methodCount
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-04-05 10:39:02 +00:00
|
|
|
getDuration metric[prometheus.Counter]
|
|
|
|
putDuration metric[prometheus.Counter]
|
|
|
|
headDuration metric[prometheus.Counter]
|
|
|
|
searchDuration metric[prometheus.Counter]
|
|
|
|
deleteDuration metric[prometheus.Counter]
|
|
|
|
rangeDuration metric[prometheus.Counter]
|
|
|
|
rangeHashDuration metric[prometheus.Counter]
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-04-05 10:39:02 +00:00
|
|
|
putPayload metric[prometheus.Counter]
|
|
|
|
getPayload metric[prometheus.Counter]
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-04-05 10:39:02 +00:00
|
|
|
shardMetrics metric[*prometheus.GaugeVec]
|
|
|
|
shardsReadonly metric[*prometheus.GaugeVec]
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-09-09 09:47:07 +00:00
|
|
|
const (
|
|
|
|
shardIDLabelKey = "shard"
|
|
|
|
counterTypeLabelKey = "type"
|
2022-12-01 11:59:22 +00:00
|
|
|
containerIDLabelKey = "cid"
|
2022-09-09 09:47:07 +00:00
|
|
|
)
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-04-05 09:43:32 +00:00
|
|
|
func newObjectMethodCallCounter(name string) methodCount {
|
2022-11-29 11:51:19 +00:00
|
|
|
return methodCount{
|
2023-04-05 10:39:02 +00:00
|
|
|
success: newCounter(prometheus.CounterOpts{
|
2021-03-16 08:14:56 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
2023-02-07 09:45:51 +00:00
|
|
|
Name: fmt.Sprintf("%s_req_count_success", name),
|
2022-11-29 11:51:19 +00:00
|
|
|
Help: fmt.Sprintf("The number of successful %s requests processed", name),
|
|
|
|
}),
|
2023-04-05 10:39:02 +00:00
|
|
|
total: newCounter(prometheus.CounterOpts{
|
2021-03-16 08:14:56 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
2023-02-07 09:45:51 +00:00
|
|
|
Name: fmt.Sprintf("%s_req_count", name),
|
2022-11-29 11:51:19 +00:00
|
|
|
Help: fmt.Sprintf("Total number of %s requests processed", name),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m methodCount) mustRegister() {
|
2023-04-05 08:44:13 +00:00
|
|
|
mustRegister(m.success)
|
|
|
|
mustRegister(m.total)
|
2022-11-29 11:51:19 +00:00
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m methodCount) Inc(success bool) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.total.value.Inc()
|
2022-11-29 11:51:19 +00:00
|
|
|
if success {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.success.value.Inc()
|
2022-11-29 11:51:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func newObjectServiceMetrics() objectServiceMetrics {
|
2023-04-05 09:43:32 +00:00
|
|
|
return objectServiceMetrics{
|
|
|
|
getCounter: newObjectMethodCallCounter("get"),
|
|
|
|
putCounter: newObjectMethodCallCounter("put"),
|
|
|
|
headCounter: newObjectMethodCallCounter("head"),
|
|
|
|
searchCounter: newObjectMethodCallCounter("search"),
|
|
|
|
deleteCounter: newObjectMethodCallCounter("delete"),
|
|
|
|
rangeCounter: newObjectMethodCallCounter("range"),
|
|
|
|
rangeHashCounter: newObjectMethodCallCounter("range_hash"),
|
|
|
|
getDuration: newObjectMethodDurationCounter("get"),
|
|
|
|
putDuration: newObjectMethodDurationCounter("put"),
|
|
|
|
headDuration: newObjectMethodDurationCounter("head"),
|
|
|
|
searchDuration: newObjectMethodDurationCounter("search"),
|
|
|
|
deleteDuration: newObjectMethodDurationCounter("delete"),
|
|
|
|
rangeDuration: newObjectMethodDurationCounter("range"),
|
|
|
|
rangeHashDuration: newObjectMethodDurationCounter("range_hash"),
|
|
|
|
putPayload: newObjectMethodPayloadCounter("put"),
|
|
|
|
getPayload: newObjectMethodPayloadCounter("get"),
|
|
|
|
shardMetrics: newObjectGaugeVector("counter", "Objects counters per shards", []string{shardIDLabelKey, counterTypeLabelKey}),
|
|
|
|
shardsReadonly: newObjectGaugeVector("readonly", "Shard state", []string{shardIDLabelKey}),
|
|
|
|
}
|
|
|
|
}
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-04-05 10:39:02 +00:00
|
|
|
func newObjectMethodPayloadCounter(method string) metric[prometheus.Counter] {
|
|
|
|
return newCounter(prometheus.CounterOpts{
|
2023-04-05 09:43:32 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
|
|
|
Name: fmt.Sprintf("%s_payload", method),
|
|
|
|
Help: fmt.Sprintf("Accumulated payload size at object %s method", strings.ReplaceAll(method, "_", " ")),
|
|
|
|
})
|
|
|
|
}
|
2022-12-09 13:52:13 +00:00
|
|
|
|
2023-04-05 10:39:02 +00:00
|
|
|
func newObjectMethodDurationCounter(method string) metric[prometheus.Counter] {
|
|
|
|
return newCounter(prometheus.CounterOpts{
|
2023-04-05 09:43:32 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
|
|
|
Name: fmt.Sprintf("%s_req_duration", method),
|
|
|
|
Help: fmt.Sprintf("Accumulated %s request process duration", strings.ReplaceAll(method, "_", " ")),
|
|
|
|
})
|
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-04-05 10:39:02 +00:00
|
|
|
func newObjectGaugeVector(name, help string, labels []string) metric[*prometheus.GaugeVec] {
|
|
|
|
return newGaugeVec(prometheus.GaugeOpts{
|
2023-04-05 09:43:32 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
|
|
|
Name: name,
|
|
|
|
Help: help,
|
|
|
|
}, labels)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) register() {
|
2022-11-29 11:51:19 +00:00
|
|
|
m.getCounter.mustRegister()
|
|
|
|
m.putCounter.mustRegister()
|
|
|
|
m.headCounter.mustRegister()
|
|
|
|
m.searchCounter.mustRegister()
|
|
|
|
m.deleteCounter.mustRegister()
|
|
|
|
m.rangeCounter.mustRegister()
|
|
|
|
m.rangeHashCounter.mustRegister()
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-04-05 08:44:13 +00:00
|
|
|
mustRegister(m.getDuration)
|
|
|
|
mustRegister(m.putDuration)
|
|
|
|
mustRegister(m.headDuration)
|
|
|
|
mustRegister(m.searchDuration)
|
|
|
|
mustRegister(m.deleteDuration)
|
|
|
|
mustRegister(m.rangeDuration)
|
|
|
|
mustRegister(m.rangeHashDuration)
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-04-05 08:44:13 +00:00
|
|
|
mustRegister(m.putPayload)
|
|
|
|
mustRegister(m.getPayload)
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-04-05 08:44:13 +00:00
|
|
|
mustRegister(m.shardMetrics)
|
|
|
|
mustRegister(m.shardsReadonly)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncGetReqCounter(success bool) {
|
|
|
|
m.getCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncPutReqCounter(success bool) {
|
|
|
|
m.putCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncHeadReqCounter(success bool) {
|
|
|
|
m.headCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncSearchReqCounter(success bool) {
|
|
|
|
m.searchCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncDeleteReqCounter(success bool) {
|
|
|
|
m.deleteCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncRangeReqCounter(success bool) {
|
|
|
|
m.rangeCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 11:51:19 +00:00
|
|
|
func (m objectServiceMetrics) IncRangeHashReqCounter(success bool) {
|
|
|
|
m.rangeHashCounter.Inc(success)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddGetReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.getDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddPutReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.putDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddHeadReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.headDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddSearchReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.searchDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddDeleteReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.deleteDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddRangeReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.rangeDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddRangeHashReqDuration(d time.Duration) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.rangeHashDuration.value.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddPutPayload(ln int) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.putPayload.value.Add(float64(ln))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m objectServiceMetrics) AddGetPayload(ln int) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.getPayload.value.Add(float64(ln))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2022-09-09 09:47:07 +00:00
|
|
|
func (m objectServiceMetrics) AddToObjectCounter(shardID, objectType string, delta int) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.shardMetrics.value.With(
|
2022-09-09 09:47:07 +00:00
|
|
|
prometheus.Labels{
|
|
|
|
shardIDLabelKey: shardID,
|
|
|
|
counterTypeLabelKey: objectType,
|
|
|
|
},
|
|
|
|
).Add(float64(delta))
|
2022-08-19 16:41:29 +00:00
|
|
|
}
|
2022-08-19 17:24:05 +00:00
|
|
|
|
2022-09-09 09:47:07 +00:00
|
|
|
func (m objectServiceMetrics) SetObjectCounter(shardID, objectType string, v uint64) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.shardMetrics.value.With(
|
2022-09-09 09:47:07 +00:00
|
|
|
prometheus.Labels{
|
|
|
|
shardIDLabelKey: shardID,
|
|
|
|
counterTypeLabelKey: objectType,
|
|
|
|
},
|
|
|
|
).Set(float64(v))
|
2022-08-19 17:24:05 +00:00
|
|
|
}
|
2022-12-09 13:52:13 +00:00
|
|
|
|
|
|
|
func (m objectServiceMetrics) SetReadonly(shardID string, readonly bool) {
|
|
|
|
var flag float64
|
|
|
|
if readonly {
|
|
|
|
flag = 1
|
|
|
|
}
|
2023-04-05 10:39:02 +00:00
|
|
|
m.shardsReadonly.value.With(
|
2022-12-09 13:52:13 +00:00
|
|
|
prometheus.Labels{
|
|
|
|
shardIDLabelKey: shardID,
|
|
|
|
},
|
|
|
|
).Set(flag)
|
|
|
|
}
|