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