2023-05-26 09:15:50 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-06-13 11:19:33 +00:00
|
|
|
"strconv"
|
2023-05-26 09:15:50 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
mcSubsystem = "morphcache"
|
|
|
|
mcSuccess = "success"
|
2023-06-13 13:15:59 +00:00
|
|
|
mcMethod = "method"
|
2023-05-26 09:15:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MorphCacheMetrics interface {
|
2023-06-13 13:15:59 +00:00
|
|
|
AddMethodDuration(method string, success bool, d time.Duration)
|
2023-05-26 09:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type morphCacheMetrics struct {
|
2023-06-13 13:15:59 +00:00
|
|
|
methodDuration *prometheus.HistogramVec
|
2023-05-26 09:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ MorphCacheMetrics = (*morphCacheMetrics)(nil)
|
|
|
|
|
|
|
|
func newMorphCacheMetrics() *morphCacheMetrics {
|
|
|
|
return &morphCacheMetrics{
|
2023-06-13 13:15:59 +00:00
|
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: mcSubsystem,
|
|
|
|
Name: "request_duration_seconds",
|
|
|
|
Help: "Morph cache request process duration",
|
|
|
|
}, []string{mcSuccess, mcMethod}),
|
2023-05-26 09:15:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 13:15:59 +00:00
|
|
|
func (m *morphCacheMetrics) AddMethodDuration(method string, success bool, d time.Duration) {
|
|
|
|
m.methodDuration.With(
|
2023-05-26 09:15:50 +00:00
|
|
|
prometheus.Labels{
|
2023-06-13 11:19:33 +00:00
|
|
|
mcSuccess: strconv.FormatBool(success),
|
2023-06-13 13:15:59 +00:00
|
|
|
mcMethod: method,
|
2023-05-26 09:15:50 +00:00
|
|
|
},
|
2023-06-13 13:15:59 +00:00
|
|
|
).Observe(d.Seconds())
|
2023-05-26 09:15:50 +00:00
|
|
|
}
|