[#680] Use gauge instead of counter for metrics

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-08-25 09:22:42 +03:00 committed by Alex Vanin
parent a217871334
commit 628c0f42fe

View file

@ -47,9 +47,9 @@ type stateMetrics struct {
type poolMetricsCollector struct {
poolStatScraper StatisticScraper
overallErrors prometheus.Counter
overallNodeErrors *prometheus.CounterVec
overallNodeRequests *prometheus.CounterVec
overallErrors prometheus.Gauge
overallNodeErrors *prometheus.GaugeVec
overallNodeRequests *prometheus.GaugeVec
currentErrors *prometheus.GaugeVec
requestDuration *prometheus.GaugeVec
}
@ -87,8 +87,8 @@ func (m stateMetrics) SetHealth(s int32) {
}
func newPoolMetricsCollector(scraper StatisticScraper) *poolMetricsCollector {
overallErrors := prometheus.NewCounter(
prometheus.CounterOpts{
overallErrors := prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: poolSubsystem,
Name: "overall_errors",
@ -96,8 +96,8 @@ func newPoolMetricsCollector(scraper StatisticScraper) *poolMetricsCollector {
},
)
overallNodeErrors := prometheus.NewCounterVec(
prometheus.CounterOpts{
overallNodeErrors := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: poolSubsystem,
Name: "overall_node_errors",
@ -108,8 +108,8 @@ func newPoolMetricsCollector(scraper StatisticScraper) *poolMetricsCollector {
},
)
overallNodeRequests := prometheus.NewCounterVec(
prometheus.CounterOpts{
overallNodeRequests := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: poolSubsystem,
Name: "overall_node_requests",
@ -179,18 +179,20 @@ func (m *poolMetricsCollector) register() {
func (m *poolMetricsCollector) updateStatistic() {
stat := m.poolStatScraper.Statistic()
m.overallNodeErrors.Reset()
m.overallNodeRequests.Reset()
m.currentErrors.Reset()
m.requestDuration.Reset()
for _, node := range stat.Nodes() {
m.overallNodeErrors.WithLabelValues(node.Address()).Add(float64(node.OverallErrors()))
m.overallNodeRequests.WithLabelValues(node.Address()).Add(float64(node.Requests()))
m.overallNodeErrors.WithLabelValues(node.Address()).Set(float64(node.OverallErrors()))
m.overallNodeRequests.WithLabelValues(node.Address()).Set(float64(node.Requests()))
m.currentErrors.WithLabelValues(node.Address()).Set(float64(node.CurrentErrors()))
m.updateRequestsDuration(node)
}
m.overallErrors.Add(float64(stat.OverallErrors()))
m.overallErrors.Set(float64(stat.OverallErrors()))
}
func (m *poolMetricsCollector) updateRequestsDuration(node pool.NodeStatistic) {