frostfs-node/pkg/metrics/gc.go

99 lines
3 KiB
Go
Raw Normal View History

package metrics
import (
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
const (
gcSubsystem = "garbage_collector"
gcShardID = "shard_id"
gcSuccess = "success"
gcStatus = "status"
gcDeleted = "deleted"
gcFailed = "failed_to_delete"
gcObjectType = "object_type"
)
type GCMetrics interface {
AddRunDuration(shardID string, d time.Duration, success bool)
AddDeletedCount(shardID string, deleted, failed uint64)
AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string)
AddInhumedObjectCount(shardID string, count uint64, objectType string)
}
type gcMetrics struct {
runDuration *prometheus.CounterVec
deletedCounter *prometheus.CounterVec
expCollectDuration *prometheus.CounterVec
inhumedCounter *prometheus.CounterVec
}
func newGCMetrics() *gcMetrics {
return &gcMetrics{
runDuration: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: gcSubsystem,
Name: "delete_duration_seconds",
Help: "The total time of GC runs to delete objects from disk",
}, []string{gcShardID, gcSuccess}),
deletedCounter: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: gcSubsystem,
Name: "deleted_objects_count",
Help: "Total count of objects GC deleted or failed to delete from disk",
}, []string{gcShardID, gcStatus}),
expCollectDuration: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: gcSubsystem,
Name: "marking_duration_seconds",
Help: "The total time of GC runs to mark expired objects as removed",
}, []string{gcShardID, gcSuccess, gcObjectType}),
inhumedCounter: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: gcSubsystem,
Name: "marked_for_removal_objects_count",
Help: "Total count of expired objects GC marked to remove",
}, []string{gcShardID, gcObjectType}),
}
}
func (m *gcMetrics) AddRunDuration(shardID string, d time.Duration, success bool) {
m.runDuration.With(prometheus.Labels{
gcShardID: shardID,
gcSuccess: strconv.FormatBool(success),
}).Add(d.Seconds())
}
func (m *gcMetrics) AddDeletedCount(shardID string, deleted, failed uint64) {
m.deletedCounter.With(
prometheus.Labels{
gcShardID: shardID,
gcStatus: gcDeleted,
}).Add(float64(deleted))
m.deletedCounter.With(
prometheus.Labels{
gcShardID: shardID,
gcStatus: gcFailed,
}).Add(float64(failed))
}
func (m *gcMetrics) AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string) {
m.expCollectDuration.With(prometheus.Labels{
gcShardID: shardID,
gcSuccess: strconv.FormatBool(success),
gcObjectType: objectType,
}).Add(d.Seconds())
}
func (m *gcMetrics) AddInhumedObjectCount(shardID string, count uint64, objectType string) {
m.inhumedCounter.With(
prometheus.Labels{
gcShardID: shardID,
gcObjectType: objectType,
}).Add(float64(count))
}