-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathmetrics.go
65 lines (56 loc) · 2.08 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2022 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
package balancer
import "github.com/cockroachdb/cockroach/pkg/util/metric"
// Metrics contains pointers to the metrics for monitoring balancer-related
// operations.
type Metrics struct {
rebalanceReqRunning *metric.Gauge
rebalanceReqQueued *metric.Gauge
rebalanceReqTotal *metric.Counter
}
// MetricStruct implements the metrics.Struct interface.
func (Metrics) MetricStruct() {}
var _ metric.Struct = Metrics{}
var (
metaRebalanceReqRunning = metric.Metadata{
Name: "proxy.balancer.rebalance.running",
Help: "Number of rebalance requests currently running",
Measurement: "Rebalance Requests",
Unit: metric.Unit_COUNT,
}
metaRebalanceReqQueued = metric.Metadata{
Name: "proxy.balancer.rebalance.queued",
Help: "Number of rebalance requests currently queued",
Measurement: "Rebalance Requests",
Unit: metric.Unit_COUNT,
}
metaRebalanceReqTotal = metric.Metadata{
Name: "proxy.balancer.rebalance.total",
Help: "Number of rebalance requests that were processed",
Measurement: "Rebalance Requests",
Unit: metric.Unit_COUNT,
}
)
// MakeMetrics instantiates the metrics holder for balancer monitoring.
func MakeMetrics() *Metrics {
return &Metrics{
rebalanceReqRunning: metric.NewGauge(metaRebalanceReqRunning),
rebalanceReqQueued: metric.NewGauge(metaRebalanceReqQueued),
rebalanceReqTotal: metric.NewCounter(metaRebalanceReqTotal),
}
}
// processRebalanceStart indicates the start of processing a rebalance request.
func (m *Metrics) processRebalanceStart() {
m.rebalanceReqRunning.Inc(1)
m.rebalanceReqTotal.Inc(1)
}
// processRebalanceFinish indicates the end of processing a rebalance request.
func (m *Metrics) processRebalanceFinish() {
m.rebalanceReqRunning.Dec(1)
}