frostfs-node/internal/metrics/cache.go

36 lines
895 B
Go
Raw Permalink Normal View History

package metrics
import (
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var cacheRequests = metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: commonCacheSubsystem,
Name: "request_duration_seconds",
Help: "Accumulated common cache request process duration",
}, []string{hitLabel, methodLabel, cacheLabel})
type CacheMetrics struct {
cache string
}
// NewCacheMetrics returns new CacheMetrics instance for cache specified.
func NewCacheMetrics(cache string) *CacheMetrics {
return &CacheMetrics{
cache: cache,
}
}
func (m *CacheMetrics) AddMethodDuration(method string, d time.Duration, hit bool) {
cacheRequests.With(prometheus.Labels{
hitLabel: strconv.FormatBool(hit),
methodLabel: method,
cacheLabel: m.cache,
}).Observe(d.Seconds())
}