-
Notifications
You must be signed in to change notification settings - Fork 726
/
Copy pathmetrics.go
147 lines (136 loc) · 5.58 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2023 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package server
import "github.com/prometheus/client_golang/prometheus"
const (
namespace = "resource_manager"
serverSubsystem = "server"
ruSubsystem = "resource_unit"
resourceSubsystem = "resource"
resourceGroupNameLabel = "name"
typeLabel = "type"
readTypeLabel = "read"
writeTypeLabel = "write"
backgroundTypeLabel = "background"
tiflashTypeLabel = "ap"
defaultTypeLabel = "tp"
newResourceGroupNameLabel = "resource_group"
// Labels for the config.
ruPerSecLabel = "ru_per_sec"
ruCapacityLabel = "ru_capacity"
priorityLabel = "priority"
)
var (
// RU cost metrics.
// `sum` is added to the name to maintain compatibility with the previous use of histogram.
readRequestUnitCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "read_request_unit_sum",
Help: "Counter of the read request unit cost for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
writeRequestUnitCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "write_request_unit_sum",
Help: "Counter of the write request unit cost for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
readRequestUnitMaxPerSecCost = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "read_request_unit_max_per_sec",
Help: "Gauge of the max read request unit per second for all resource groups.",
}, []string{newResourceGroupNameLabel})
writeRequestUnitMaxPerSecCost = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "write_request_unit_max_per_sec",
Help: "Gauge of the max write request unit per second for all resource groups.",
}, []string{newResourceGroupNameLabel})
sqlLayerRequestUnitCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "sql_layer_request_unit_sum",
Help: "The number of the sql layer request unit cost for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel})
// Resource cost metrics.
readByteCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "read_byte_sum",
Help: "Counter of the read byte cost for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
writeByteCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "write_byte_sum",
Help: "Counter of the write byte cost for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
kvCPUCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "kv_cpu_time_ms_sum",
Help: "Counter of the KV CPU time cost in milliseconds for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
sqlCPUCost = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "sql_cpu_time_ms_sum",
Help: "Counter of the SQL CPU time cost in milliseconds for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
requestCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: resourceSubsystem,
Name: "request_count",
Help: "The number of read/write requests for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel, typeLabel})
availableRUCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: ruSubsystem,
Name: "available_ru",
Help: "Counter of the available RU for all resource groups.",
}, []string{resourceGroupNameLabel, newResourceGroupNameLabel})
resourceGroupConfigGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: serverSubsystem,
Name: "group_config",
Help: "Config of the resource group.",
}, []string{newResourceGroupNameLabel, typeLabel})
)
func init() {
prometheus.MustRegister(readRequestUnitCost)
prometheus.MustRegister(writeRequestUnitCost)
prometheus.MustRegister(sqlLayerRequestUnitCost)
prometheus.MustRegister(readByteCost)
prometheus.MustRegister(writeByteCost)
prometheus.MustRegister(kvCPUCost)
prometheus.MustRegister(sqlCPUCost)
prometheus.MustRegister(requestCount)
prometheus.MustRegister(availableRUCounter)
prometheus.MustRegister(readRequestUnitMaxPerSecCost)
prometheus.MustRegister(writeRequestUnitMaxPerSecCost)
prometheus.MustRegister(resourceGroupConfigGauge)
}