forked from TrueCloudLab/frostfs-s3-gw
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
|
package metrics
|
||
|
|
||
|
import (
|
||
|
"github.com/prometheus/client_golang/prometheus"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
treePoolSubsystem = "tree_pool"
|
||
|
|
||
|
methodGetNodes = "get_nodes"
|
||
|
methodGetSubTree = "get_sub_tree"
|
||
|
methodAddNode = "add_node"
|
||
|
methodAddNodeByPath = "add_node_by_path"
|
||
|
methodMoveNode = "move_node"
|
||
|
methodRemoveNode = "remove_node"
|
||
|
)
|
||
|
|
||
|
type treePoolMetricsCollector struct {
|
||
|
statScraper TreePoolStatistic
|
||
|
requestDuration *prometheus.GaugeVec
|
||
|
}
|
||
|
|
||
|
func newTreePoolMetricsCollector(stat TreePoolStatistic) *treePoolMetricsCollector {
|
||
|
return &treePoolMetricsCollector{
|
||
|
statScraper: stat,
|
||
|
requestDuration: mustNewGaugeVec(appMetricsDesc[treePoolSubsystem][avgRequestDurationMetric]),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *treePoolMetricsCollector) Collect(ch chan<- prometheus.Metric) {
|
||
|
m.updateStatistic()
|
||
|
m.requestDuration.Collect(ch)
|
||
|
}
|
||
|
|
||
|
func (m *treePoolMetricsCollector) Describe(descs chan<- *prometheus.Desc) {
|
||
|
m.requestDuration.Describe(descs)
|
||
|
}
|
||
|
|
||
|
func (m *treePoolMetricsCollector) updateStatistic() {
|
||
|
stat := m.statScraper.Statistic()
|
||
|
|
||
|
m.requestDuration.Reset()
|
||
|
|
||
|
m.requestDuration.WithLabelValues(methodGetNodes).Set(float64(stat.AverageGetNodes().Milliseconds()))
|
||
|
m.requestDuration.WithLabelValues(methodGetSubTree).Set(float64(stat.AverageGetSubTree().Milliseconds()))
|
||
|
m.requestDuration.WithLabelValues(methodAddNode).Set(float64(stat.AverageAddNode().Milliseconds()))
|
||
|
m.requestDuration.WithLabelValues(methodAddNodeByPath).Set(float64(stat.AverageAddNodeByPath().Milliseconds()))
|
||
|
m.requestDuration.WithLabelValues(methodMoveNode).Set(float64(stat.AverageMoveNode().Milliseconds()))
|
||
|
m.requestDuration.WithLabelValues(methodRemoveNode).Set(float64(stat.AverageRemoveNode().Milliseconds()))
|
||
|
}
|