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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2023-06-14 09:12:47 +00:00
|
|
|
func NewNodeMorphCacheMetrics() MorphCacheMetrics {
|
|
|
|
return newMorphCacheMetrics(namespace)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMorphCacheMetrics(ns string) *morphCacheMetrics {
|
2023-05-26 09:15:50 +00:00
|
|
|
return &morphCacheMetrics{
|
2023-06-13 13:15:59 +00:00
|
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2023-06-14 09:12:47 +00:00
|
|
|
Namespace: ns,
|
2023-06-16 07:13:22 +00:00
|
|
|
Subsystem: morphCacheSubsystem,
|
2023-06-13 13:15:59 +00:00
|
|
|
Name: "request_duration_seconds",
|
|
|
|
Help: "Morph cache request process duration",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{successLabel, methodLabel}),
|
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-16 07:13:22 +00:00
|
|
|
successLabel: strconv.FormatBool(success),
|
|
|
|
methodLabel: 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
|
|
|
}
|