forked from TrueCloudLab/frostfs-node
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package metrics
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
const treeServiceLabelSuccess = "success"
|
|
|
|
type treeServiceMetrics struct {
|
|
replicateTaskDuration metric[*prometheus.HistogramVec]
|
|
replicateWaitDuration metric[*prometheus.HistogramVec]
|
|
syncOpDuration metric[*prometheus.HistogramVec]
|
|
}
|
|
|
|
func newTreeServiceMetrics() *treeServiceMetrics {
|
|
const treeServiceSubsystem = "treeservice"
|
|
return &treeServiceMetrics{
|
|
replicateTaskDuration: newHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: namespace,
|
|
Subsystem: treeServiceSubsystem,
|
|
Name: "replicate_task_duration_seconds",
|
|
Help: "Duration of individual replication tasks executed as part of replication loops",
|
|
}, []string{treeServiceLabelSuccess}),
|
|
replicateWaitDuration: newHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: namespace,
|
|
Subsystem: treeServiceSubsystem,
|
|
Name: "replicate_wait_duration_seconds",
|
|
Help: "Duration of overall waiting time for replication loops",
|
|
}, []string{treeServiceLabelSuccess}),
|
|
syncOpDuration: newHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: namespace,
|
|
Subsystem: treeServiceSubsystem,
|
|
Name: "sync_duration_seconds",
|
|
Help: "Duration of synchronization operations",
|
|
}, []string{treeServiceLabelSuccess}),
|
|
}
|
|
}
|
|
|
|
func (m *treeServiceMetrics) register() {
|
|
mustRegister(m.replicateTaskDuration)
|
|
mustRegister(m.replicateWaitDuration)
|
|
mustRegister(m.syncOpDuration)
|
|
}
|
|
|
|
func (m *treeServiceMetrics) AddReplicateTaskDuration(d time.Duration, success bool) {
|
|
m.replicateTaskDuration.value.With(prometheus.Labels{
|
|
treeServiceLabelSuccess: fmt.Sprintf("%v", success),
|
|
}).Observe(d.Seconds())
|
|
}
|
|
|
|
func (m *treeServiceMetrics) AddReplicateWaitDuration(d time.Duration, success bool) {
|
|
m.replicateWaitDuration.value.With(prometheus.Labels{
|
|
treeServiceLabelSuccess: fmt.Sprintf("%v", success),
|
|
}).Observe(d.Seconds())
|
|
}
|
|
|
|
func (m *treeServiceMetrics) AddSyncDuration(d time.Duration, success bool) {
|
|
m.syncOpDuration.value.With(prometheus.Labels{
|
|
treeServiceLabelSuccess: fmt.Sprintf("%v", success),
|
|
}).Observe(d.Seconds())
|
|
}
|