2021-03-16 08:14:56 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-06-14 08:00:44 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
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"
|
|
|
|
)
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
type EngineMetrics interface {
|
|
|
|
AddMethodDuration(method string, d time.Duration)
|
|
|
|
AddToContainerSize(cnrID string, size int64)
|
|
|
|
IncErrorCounter(shardID string)
|
|
|
|
ClearErrorCounter(shardID string)
|
|
|
|
DeleteShardMetrics(shardID string)
|
|
|
|
AddToObjectCounter(shardID, objectType string, delta int)
|
|
|
|
SetObjectCounter(shardID, objectType string, v uint64)
|
|
|
|
AddToPayloadCounter(shardID string, size int64)
|
2023-06-14 08:00:44 +00:00
|
|
|
SetMode(shardID string, mode mode.Mode)
|
2023-06-13 16:48:15 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
WriteCache() WriteCacheMetrics
|
|
|
|
GC() GCMetrics
|
|
|
|
}
|
|
|
|
|
|
|
|
type engineMetrics struct {
|
|
|
|
methodDuration *prometheus.HistogramVec
|
|
|
|
objectCounter *prometheus.GaugeVec
|
|
|
|
containerSize *prometheus.GaugeVec
|
|
|
|
payloadSize *prometheus.GaugeVec
|
|
|
|
errorCounter *prometheus.GaugeVec
|
2023-06-14 08:00:44 +00:00
|
|
|
mode *shardIDModeValue
|
2023-06-14 07:05:51 +00:00
|
|
|
|
|
|
|
gc *gcMetrics
|
|
|
|
writeCache *writeCacheMetrics
|
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func newEngineMetrics() *engineMetrics {
|
|
|
|
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}),
|
2023-06-16 07:13:22 +00:00
|
|
|
payloadSize: newEngineGaugeVector("payload_size_bytes", "Accumulated size of all objects in a shard", []string{shardIDLabel}),
|
|
|
|
errorCounter: newEngineGaugeVector("errors_total", "Shard's error counter", []string{shardIDLabel}),
|
2023-06-13 16:48:15 +00:00
|
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: engineSubsystem,
|
|
|
|
Name: "request_duration_seconds",
|
|
|
|
Help: "Duration of Engine requests",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{methodLabel}),
|
|
|
|
objectCounter: newEngineGaugeVector("objects_total", "Objects counters per shards", []string{shardIDLabel, typeLabel}),
|
2023-06-14 08:00:44 +00:00
|
|
|
gc: newGCMetrics(),
|
|
|
|
writeCache: newWriteCacheMetrics(),
|
2023-06-14 15:39:49 +00:00
|
|
|
mode: newShardIDMode(engineSubsystem, "mode_info", "Shard mode"),
|
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{
|
2023-06-16 07:13:22 +00:00
|
|
|
methodLabel: method,
|
2023-06-13 16:48:15 +00:00
|
|
|
}).Observe(d.Seconds())
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
|
2023-06-14 07:05:51 +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
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *engineMetrics) AddToPayloadCounter(shardID string, size int64) {
|
2023-06-16 07:13:22 +00:00
|
|
|
m.payloadSize.With(prometheus.Labels{shardIDLabel: shardID}).Add(float64(size))
|
2023-01-25 14:01:25 +00:00
|
|
|
}
|
2023-06-01 14:28:04 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *engineMetrics) IncErrorCounter(shardID string) {
|
2023-06-16 07:13:22 +00:00
|
|
|
m.errorCounter.With(prometheus.Labels{shardIDLabel: shardID}).Inc()
|
2023-06-01 14:28:04 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *engineMetrics) ClearErrorCounter(shardID string) {
|
2023-06-16 07:13:22 +00:00
|
|
|
m.errorCounter.With(prometheus.Labels{shardIDLabel: shardID}).Set(0)
|
2023-06-01 14:28:04 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *engineMetrics) DeleteShardMetrics(shardID string) {
|
2023-06-16 07:13:22 +00:00
|
|
|
m.errorCounter.Delete(prometheus.Labels{shardIDLabel: shardID})
|
|
|
|
m.payloadSize.Delete(prometheus.Labels{shardIDLabel: shardID})
|
|
|
|
m.objectCounter.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID})
|
2023-06-14 08:00:44 +00:00
|
|
|
m.mode.Delete(shardID)
|
2023-06-14 07:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *engineMetrics) AddToObjectCounter(shardID, objectType string, delta int) {
|
|
|
|
m.objectCounter.With(
|
|
|
|
prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
typeLabel: objectType,
|
2023-06-14 07:05:51 +00:00
|
|
|
},
|
|
|
|
).Add(float64(delta))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *engineMetrics) SetObjectCounter(shardID, objectType string, v uint64) {
|
|
|
|
m.objectCounter.With(
|
|
|
|
prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
typeLabel: objectType,
|
2023-06-14 07:05:51 +00:00
|
|
|
},
|
|
|
|
).Set(float64(v))
|
|
|
|
}
|
|
|
|
|
2023-06-14 08:00:44 +00:00
|
|
|
func (m *engineMetrics) SetMode(shardID string, mode mode.Mode) {
|
|
|
|
m.mode.SetMode(shardID, mode.String())
|
2023-06-14 07:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *engineMetrics) WriteCache() WriteCacheMetrics {
|
|
|
|
return m.writeCache
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *engineMetrics) GC() GCMetrics {
|
|
|
|
return m.gc
|
2023-06-01 14:28:04 +00:00
|
|
|
}
|