frostfs-node/pkg/metrics/morphcache.go
Dmitrii Stepanov 03aa210145 [#373] metrics: Move labels to consts
To unify label naming all lable keys and other consts are moved to
one file.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-06-21 15:13:26 +03:00

43 lines
1.1 KiB
Go

package metrics
import (
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type MorphCacheMetrics interface {
AddMethodDuration(method string, success bool, d time.Duration)
}
type morphCacheMetrics struct {
methodDuration *prometheus.HistogramVec
}
var _ MorphCacheMetrics = (*morphCacheMetrics)(nil)
func NewNodeMorphCacheMetrics() MorphCacheMetrics {
return newMorphCacheMetrics(namespace)
}
func newMorphCacheMetrics(ns string) *morphCacheMetrics {
return &morphCacheMetrics{
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: ns,
Subsystem: morphCacheSubsystem,
Name: "request_duration_seconds",
Help: "Morph cache request process duration",
}, []string{successLabel, methodLabel}),
}
}
func (m *morphCacheMetrics) AddMethodDuration(method string, success bool, d time.Duration) {
m.methodDuration.With(
prometheus.Labels{
successLabel: strconv.FormatBool(success),
methodLabel: method,
},
).Observe(d.Seconds())
}