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"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
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",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{methodLabel, successLabel}),
|
2023-06-14 07:05:51 +00:00
|
|
|
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",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{methodLabel}),
|
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{
|
2023-06-16 07:13:22 +00:00
|
|
|
methodLabel: method,
|
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-06-14 07:05:51 +00:00
|
|
|
}).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{
|
2023-06-16 07:13:22 +00:00
|
|
|
methodLabel: method,
|
2023-06-14 07:05:51 +00:00
|
|
|
}).Add(float64(size))
|
2022-12-09 13:52:13 +00:00
|
|
|
}
|