2021-03-16 08:14:56 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-06-14 07:05:51 +00:00
|
|
|
"strconv"
|
2021-03-16 08:14:56 +00:00
|
|
|
"time"
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
2021-03-16 08:14:56 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
const objectSubsystem = "object"
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
type ObjectServiceMetrics interface {
|
|
|
|
AddRequestDuration(method string, d time.Duration, success bool)
|
|
|
|
AddPayloadSize(method string, size int)
|
|
|
|
}
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
type objectServiceMetrics struct {
|
|
|
|
methodDuration *prometheus.HistogramVec
|
|
|
|
payloadCounter *prometheus.CounterVec
|
|
|
|
}
|
2021-03-16 08:14:56 +00:00
|
|
|
|
2022-09-09 09:47:07 +00:00
|
|
|
const (
|
|
|
|
shardIDLabelKey = "shard"
|
|
|
|
counterTypeLabelKey = "type"
|
2022-12-01 11:59:22 +00:00
|
|
|
containerIDLabelKey = "cid"
|
2023-06-14 07:05:51 +00:00
|
|
|
methodLabelKey = "method"
|
|
|
|
successLabelKey = "success"
|
2022-09-09 09:47:07 +00:00
|
|
|
)
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func newObjectServiceMetrics() *objectServiceMetrics {
|
|
|
|
return &objectServiceMetrics{
|
|
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2021-03-16 08:14:56 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
2023-06-14 07:05:51 +00:00
|
|
|
Name: "request_duration_seconds",
|
|
|
|
Help: "Object Service request process duration",
|
|
|
|
}, []string{methodLabelKey, successLabelKey}),
|
|
|
|
payloadCounter: metrics.NewCounterVec(prometheus.CounterOpts{
|
2021-03-16 08:14:56 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: objectSubsystem,
|
2023-06-14 07:05:51 +00:00
|
|
|
Name: "request_payload_bytes",
|
|
|
|
Help: "Object Service request payload",
|
|
|
|
}, []string{methodLabelKey}),
|
2023-04-05 09:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-19 16:41:29 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
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())
|
2021-03-16 08:14:56 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *objectServiceMetrics) AddPayloadSize(method string, size int) {
|
|
|
|
m.payloadCounter.With(prometheus.Labels{
|
|
|
|
methodLabelKey: method,
|
|
|
|
}).Add(float64(size))
|
2022-12-09 13:52:13 +00:00
|
|
|
}
|