2021-03-16 08:14:56 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-04-05 09:28:41 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2021-03-16 08:14:56 +00:00
|
|
|
"time"
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
2021-03-16 08:14:56 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
engineMetrics struct {
|
2023-05-31 09:25:32 +00:00
|
|
|
listContainersDuration prometheus.Counter
|
|
|
|
estimateContainerSizeDuration prometheus.Counter
|
|
|
|
deleteDuration prometheus.Counter
|
|
|
|
existsDuration prometheus.Counter
|
|
|
|
getDuration prometheus.Counter
|
|
|
|
headDuration prometheus.Counter
|
|
|
|
inhumeDuration prometheus.Counter
|
|
|
|
putDuration prometheus.Counter
|
|
|
|
rangeDuration prometheus.Counter
|
|
|
|
searchDuration prometheus.Counter
|
|
|
|
listObjectsDuration prometheus.Counter
|
|
|
|
containerSize *prometheus.GaugeVec
|
|
|
|
payloadSize *prometheus.GaugeVec
|
2023-06-01 14:28:04 +00:00
|
|
|
errorCounter *prometheus.GaugeVec
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const engineSubsystem = "engine"
|
|
|
|
|
|
|
|
func newEngineMetrics() engineMetrics {
|
2023-04-05 09:28:41 +00:00
|
|
|
return engineMetrics{
|
|
|
|
listContainersDuration: newEngineMethodDurationCounter("list_containers_"),
|
|
|
|
estimateContainerSizeDuration: newEngineCounter("estimate_container_size_duration", "Accumulated duration of engine container size estimate operations"),
|
|
|
|
deleteDuration: newEngineMethodDurationCounter("delete"),
|
|
|
|
existsDuration: newEngineMethodDurationCounter("exists"),
|
|
|
|
getDuration: newEngineMethodDurationCounter("get"),
|
|
|
|
headDuration: newEngineMethodDurationCounter("head"),
|
|
|
|
inhumeDuration: newEngineMethodDurationCounter("inhume"),
|
|
|
|
putDuration: newEngineMethodDurationCounter("put"),
|
|
|
|
rangeDuration: newEngineMethodDurationCounter("range"),
|
|
|
|
searchDuration: newEngineMethodDurationCounter("search"),
|
|
|
|
listObjectsDuration: newEngineMethodDurationCounter("list_objects"),
|
2023-04-05 10:39:02 +00:00
|
|
|
containerSize: newEngineGaugeVector("container_size", "Accumulated size of all objects in a container", []string{containerIDLabelKey}),
|
|
|
|
payloadSize: newEngineGaugeVector("payload_size", "Accumulated size of all objects in a shard", []string{shardIDLabelKey}),
|
2023-06-01 14:28:04 +00:00
|
|
|
errorCounter: newEngineGaugeVector("error_counter", "Shard's error counter", []string{shardIDLabelKey}),
|
2023-04-05 09:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
func newEngineCounter(name, help string) prometheus.Counter {
|
|
|
|
return metrics.NewCounter(prometheus.CounterOpts{
|
2023-04-05 09:28:41 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: engineSubsystem,
|
|
|
|
Name: name,
|
|
|
|
Help: help,
|
|
|
|
})
|
|
|
|
}
|
2023-01-25 14:01:25 +00:00
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
func newEngineMethodDurationCounter(method string) prometheus.Counter {
|
2023-04-05 09:28:41 +00:00
|
|
|
return newEngineCounter(
|
|
|
|
fmt.Sprintf("%s_duration", method),
|
|
|
|
fmt.Sprintf("Accumulated duration of engine %s operations", strings.ReplaceAll(method, "_", " ")),
|
2021-03-16 08:14:56 +00:00
|
|
|
)
|
2023-04-05 09:28:41 +00:00
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
func newEngineGaugeVector(name, help string, labels []string) *prometheus.GaugeVec {
|
|
|
|
return metrics.NewGaugeVec(prometheus.GaugeOpts{
|
2023-04-05 09:28:41 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: engineSubsystem,
|
|
|
|
Name: name,
|
|
|
|
Help: help,
|
|
|
|
}, labels)
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddListContainersDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.listObjectsDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddEstimateContainerSizeDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.estimateContainerSizeDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddDeleteDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.deleteDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddExistsDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.existsDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddGetDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.getDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddHeadDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.headDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddInhumeDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.inhumeDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddPutDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.putDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddRangeDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.rangeDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddSearchDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.searchDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) AddListObjectsDuration(d time.Duration) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.listObjectsDuration.Add(float64(d))
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
|
|
|
|
func (m engineMetrics) AddToContainerSize(cnrID string, size int64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.containerSize.With(prometheus.Labels{containerIDLabelKey: cnrID}).Add(float64(size))
|
2022-12-01 11:59:22 +00:00
|
|
|
}
|
2023-01-25 14:01:25 +00:00
|
|
|
|
|
|
|
func (m engineMetrics) AddToPayloadCounter(shardID string, size int64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.payloadSize.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size))
|
2023-01-25 14:01:25 +00:00
|
|
|
}
|
2023-06-01 14:28:04 +00:00
|
|
|
|
|
|
|
func (m engineMetrics) IncErrorCounter(shardID string) {
|
|
|
|
m.errorCounter.With(prometheus.Labels{shardIDLabelKey: shardID}).Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) ClearErrorCounter(shardID string) {
|
|
|
|
m.errorCounter.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m engineMetrics) DeleteErrorCounter(shardID string) {
|
|
|
|
m.errorCounter.Delete(prometheus.Labels{shardIDLabelKey: shardID})
|
|
|
|
}
|