60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package metrics
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
const objectSubsystem = "object"
|
|
|
|
type ObjectServiceMetrics interface {
|
|
AddRequestDuration(method string, d time.Duration, success bool)
|
|
AddPayloadSize(method string, size int)
|
|
}
|
|
|
|
type objectServiceMetrics struct {
|
|
methodDuration *prometheus.HistogramVec
|
|
payloadCounter *prometheus.CounterVec
|
|
}
|
|
|
|
const (
|
|
shardIDLabelKey = "shard"
|
|
counterTypeLabelKey = "type"
|
|
containerIDLabelKey = "cid"
|
|
methodLabelKey = "method"
|
|
successLabelKey = "success"
|
|
)
|
|
|
|
func newObjectServiceMetrics() *objectServiceMetrics {
|
|
return &objectServiceMetrics{
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: namespace,
|
|
Subsystem: objectSubsystem,
|
|
Name: "request_duration_seconds",
|
|
Help: "Object Service request process duration",
|
|
}, []string{methodLabelKey, successLabelKey}),
|
|
payloadCounter: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: namespace,
|
|
Subsystem: objectSubsystem,
|
|
Name: "request_payload_bytes",
|
|
Help: "Object Service request payload",
|
|
}, []string{methodLabelKey}),
|
|
}
|
|
}
|
|
|
|
func (m *objectServiceMetrics) AddRequestDuration(method string, d time.Duration, success bool) {
|
|
m.methodDuration.With(prometheus.Labels{
|
|
methodLabelKey: method,
|
|
successLabelKey: strconv.FormatBool(success),
|
|
}).Observe(d.Seconds())
|
|
}
|
|
|
|
func (m *objectServiceMetrics) AddPayloadSize(method string, size int) {
|
|
m.payloadCounter.With(prometheus.Labels{
|
|
methodLabelKey: method,
|
|
}).Add(float64(size))
|
|
}
|