2021-03-16 08:14:56 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-06-13 16:48:15 +00:00
|
|
|
methodDuration *prometheus.HistogramVec
|
|
|
|
|
|
|
|
containerSize *prometheus.GaugeVec
|
|
|
|
payloadSize *prometheus.GaugeVec
|
|
|
|
errorCounter *prometheus.GaugeVec
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-06-13 16:48:15 +00:00
|
|
|
const (
|
|
|
|
engineSubsystem = "engine"
|
|
|
|
engineMethod = "method"
|
|
|
|
)
|
2021-03-16 08:14:56 +00:00
|
|
|
|
|
|
|
func newEngineMetrics() engineMetrics {
|
2023-04-05 09:28:41 +00:00
|
|
|
return engineMetrics{
|
2023-06-13 16:48:15 +00:00
|
|
|
containerSize: newEngineGaugeVector("container_size_bytes", "Accumulated size of all objects in a container", []string{containerIDLabelKey}),
|
|
|
|
payloadSize: newEngineGaugeVector("payload_size_bytes", "Accumulated size of all objects in a shard", []string{shardIDLabelKey}),
|
|
|
|
errorCounter: newEngineGaugeVector("error_counter", "Shard's error counter", []string{shardIDLabelKey}),
|
|
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: engineSubsystem,
|
|
|
|
Name: "request_duration_seconds",
|
|
|
|
Help: "Duration of Engine requests",
|
|
|
|
}, []string{engineMethod}),
|
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 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
|
|
|
}
|
|
|
|
|
2023-06-13 16:48:15 +00:00
|
|
|
func (m *engineMetrics) AddMethodDuration(method string, d time.Duration) {
|
|
|
|
m.methodDuration.With(prometheus.Labels{
|
|
|
|
engineMethod: method,
|
|
|
|
}).Observe(d.Seconds())
|
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)
|
|
|
|
}
|
|
|
|
|
2023-06-13 16:48:15 +00:00
|
|
|
func (m engineMetrics) DeleteShardMetrics(shardID string) {
|
2023-06-01 14:28:04 +00:00
|
|
|
m.errorCounter.Delete(prometheus.Labels{shardIDLabelKey: shardID})
|
2023-06-13 16:48:15 +00:00
|
|
|
m.payloadSize.Delete(prometheus.Labels{shardIDLabelKey: shardID})
|
2023-06-01 14:28:04 +00:00
|
|
|
}
|