forked from TrueCloudLab/frostfs-node
98 lines
3 KiB
Go
98 lines
3 KiB
Go
package metrics
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
type BadgerStoreMetrics interface {
|
|
SetMode(shardID, path string, readOnly bool)
|
|
Close(shardID, path string)
|
|
MethodDuration(shardID, path string, method string, d time.Duration, success bool)
|
|
AddPut(shardID, path string, size int)
|
|
AddGet(shardID, path string, size int)
|
|
}
|
|
|
|
var _ BadgerStoreMetrics = (*badgerStoreMetrics)(nil)
|
|
|
|
type badgerStoreMetrics struct {
|
|
mode *shardIDPathModeValue
|
|
reqDuration *prometheus.HistogramVec
|
|
put *prometheus.CounterVec
|
|
get *prometheus.CounterVec
|
|
}
|
|
|
|
func newbadgerStoreMetrics() *badgerStoreMetrics {
|
|
return &badgerStoreMetrics{
|
|
mode: newShardIDPathMode(badgerStoreSubSystem, "mode", "BadgerStore mode"),
|
|
reqDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: namespace,
|
|
Subsystem: badgerStoreSubSystem,
|
|
Name: "request_duration_seconds",
|
|
Help: "Accumulated BadgerStore request process duration",
|
|
}, []string{shardIDLabel, pathLabel, successLabel, methodLabel}),
|
|
put: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: namespace,
|
|
Subsystem: badgerStoreSubSystem,
|
|
Name: "put_bytes",
|
|
Help: "Accumulated payload size written to BadgerStore",
|
|
}, []string{shardIDLabel, pathLabel}),
|
|
get: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: namespace,
|
|
Subsystem: badgerStoreSubSystem,
|
|
Name: "get_bytes",
|
|
Help: "Accumulated payload size read from BadgerStore",
|
|
}, []string{shardIDLabel, pathLabel}),
|
|
}
|
|
}
|
|
|
|
// AddGet implements BadgerStoreMetrics.
|
|
func (b *badgerStoreMetrics) AddGet(shardID string, path string, size int) {
|
|
b.get.With(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
}).Add(float64(size))
|
|
}
|
|
|
|
// AddPut implements BadgerStoreMetrics.
|
|
func (b *badgerStoreMetrics) AddPut(shardID string, path string, size int) {
|
|
b.put.With(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
}).Add(float64(size))
|
|
}
|
|
|
|
// Close implements BadgerStoreMetrics.
|
|
func (b *badgerStoreMetrics) Close(shardID string, path string) {
|
|
b.mode.SetMode(shardID, path, closedMode)
|
|
b.reqDuration.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
})
|
|
b.get.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
})
|
|
b.put.DeletePartialMatch(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
})
|
|
}
|
|
|
|
// MethodDuration implements BadgerStoreMetrics.
|
|
func (b *badgerStoreMetrics) MethodDuration(shardID string, path string, method string, d time.Duration, success bool) {
|
|
b.reqDuration.With(prometheus.Labels{
|
|
shardIDLabel: shardID,
|
|
pathLabel: path,
|
|
successLabel: strconv.FormatBool(success),
|
|
methodLabel: method,
|
|
}).Observe(d.Seconds())
|
|
}
|
|
|
|
// SetMode implements BadgerStoreMetrics.
|
|
func (b *badgerStoreMetrics) SetMode(shardID string, path string, readOnly bool) {
|
|
b.mode.SetMode(shardID, path, modeFromBool(readOnly))
|
|
}
|