blob: 7526ee4b593a08368fc2a1fd193e548eabdc51c4 [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001// Copyright 2015 The etcd Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package mvcc
16
17import (
18 "sync"
19
20 "github.com/prometheus/client_golang/prometheus"
21)
22
23var (
24 rangeCounter = prometheus.NewCounter(
25 prometheus.CounterOpts{
26 Namespace: "etcd",
27 Subsystem: "mvcc",
28 Name: "range_total",
29 Help: "Total number of ranges seen by this member.",
30 })
31 rangeCounterDebug = prometheus.NewCounter(
32 prometheus.CounterOpts{
33 Namespace: "etcd_debugging",
34 Subsystem: "mvcc",
35 Name: "range_total",
36 Help: "Total number of ranges seen by this member.",
37 })
38
39 putCounter = prometheus.NewCounter(
40 prometheus.CounterOpts{
41 Namespace: "etcd",
42 Subsystem: "mvcc",
43 Name: "put_total",
44 Help: "Total number of puts seen by this member.",
45 })
46 // TODO: remove in 3.5 release
47 putCounterDebug = prometheus.NewCounter(
48 prometheus.CounterOpts{
49 Namespace: "etcd_debugging",
50 Subsystem: "mvcc",
51 Name: "put_total",
52 Help: "Total number of puts seen by this member.",
53 })
54
55 deleteCounter = prometheus.NewCounter(
56 prometheus.CounterOpts{
57 Namespace: "etcd",
58 Subsystem: "mvcc",
59 Name: "delete_total",
60 Help: "Total number of deletes seen by this member.",
61 })
62 // TODO: remove in 3.5 release
63 deleteCounterDebug = prometheus.NewCounter(
64 prometheus.CounterOpts{
65 Namespace: "etcd_debugging",
66 Subsystem: "mvcc",
67 Name: "delete_total",
68 Help: "Total number of deletes seen by this member.",
69 })
70
71 txnCounter = prometheus.NewCounter(
72 prometheus.CounterOpts{
73 Namespace: "etcd",
74 Subsystem: "mvcc",
75 Name: "txn_total",
76 Help: "Total number of txns seen by this member.",
77 })
78 txnCounterDebug = prometheus.NewCounter(
79 prometheus.CounterOpts{
80 Namespace: "etcd_debugging",
81 Subsystem: "mvcc",
82 Name: "txn_total",
83 Help: "Total number of txns seen by this member.",
84 })
85
86 keysGauge = prometheus.NewGauge(
87 prometheus.GaugeOpts{
88 Namespace: "etcd_debugging",
89 Subsystem: "mvcc",
90 Name: "keys_total",
91 Help: "Total number of keys.",
92 })
93
94 watchStreamGauge = prometheus.NewGauge(
95 prometheus.GaugeOpts{
96 Namespace: "etcd_debugging",
97 Subsystem: "mvcc",
98 Name: "watch_stream_total",
99 Help: "Total number of watch streams.",
100 })
101
102 watcherGauge = prometheus.NewGauge(
103 prometheus.GaugeOpts{
104 Namespace: "etcd_debugging",
105 Subsystem: "mvcc",
106 Name: "watcher_total",
107 Help: "Total number of watchers.",
108 })
109
110 slowWatcherGauge = prometheus.NewGauge(
111 prometheus.GaugeOpts{
112 Namespace: "etcd_debugging",
113 Subsystem: "mvcc",
114 Name: "slow_watcher_total",
115 Help: "Total number of unsynced slow watchers.",
116 })
117
118 totalEventsCounter = prometheus.NewCounter(
119 prometheus.CounterOpts{
120 Namespace: "etcd_debugging",
121 Subsystem: "mvcc",
122 Name: "events_total",
123 Help: "Total number of events sent by this member.",
124 })
125
126 pendingEventsGauge = prometheus.NewGauge(
127 prometheus.GaugeOpts{
128 Namespace: "etcd_debugging",
129 Subsystem: "mvcc",
130 Name: "pending_events_total",
131 Help: "Total number of pending events to be sent.",
132 })
133
134 indexCompactionPauseMs = prometheus.NewHistogram(
135 prometheus.HistogramOpts{
136 Namespace: "etcd_debugging",
137 Subsystem: "mvcc",
138 Name: "index_compaction_pause_duration_milliseconds",
139 Help: "Bucketed histogram of index compaction pause duration.",
140
141 // lowest bucket start of upper bound 0.5 ms with factor 2
142 // highest bucket start of 0.5 ms * 2^13 == 4.096 sec
143 Buckets: prometheus.ExponentialBuckets(0.5, 2, 14),
144 })
145
146 dbCompactionPauseMs = prometheus.NewHistogram(
147 prometheus.HistogramOpts{
148 Namespace: "etcd_debugging",
149 Subsystem: "mvcc",
150 Name: "db_compaction_pause_duration_milliseconds",
151 Help: "Bucketed histogram of db compaction pause duration.",
152
153 // lowest bucket start of upper bound 1 ms with factor 2
154 // highest bucket start of 1 ms * 2^12 == 4.096 sec
155 Buckets: prometheus.ExponentialBuckets(1, 2, 13),
156 })
157
158 dbCompactionTotalMs = prometheus.NewHistogram(
159 prometheus.HistogramOpts{
160 Namespace: "etcd_debugging",
161 Subsystem: "mvcc",
162 Name: "db_compaction_total_duration_milliseconds",
163 Help: "Bucketed histogram of db compaction total duration.",
164
165 // lowest bucket start of upper bound 100 ms with factor 2
166 // highest bucket start of 100 ms * 2^13 == 8.192 sec
167 Buckets: prometheus.ExponentialBuckets(100, 2, 14),
168 })
169
170 dbCompactionKeysCounter = prometheus.NewCounter(
171 prometheus.CounterOpts{
172 Namespace: "etcd_debugging",
173 Subsystem: "mvcc",
174 Name: "db_compaction_keys_total",
175 Help: "Total number of db keys compacted.",
176 })
177
178 dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
179 Namespace: "etcd",
180 Subsystem: "mvcc",
181 Name: "db_total_size_in_bytes",
182 Help: "Total size of the underlying database physically allocated in bytes.",
183 },
184 func() float64 {
185 reportDbTotalSizeInBytesMu.RLock()
186 defer reportDbTotalSizeInBytesMu.RUnlock()
187 return reportDbTotalSizeInBytes()
188 },
189 )
190 // overridden by mvcc initialization
191 reportDbTotalSizeInBytesMu sync.RWMutex
192 reportDbTotalSizeInBytes = func() float64 { return 0 }
193
194 // TODO: remove this in v3.5
195 dbTotalSizeDebug = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
196 Namespace: "etcd_debugging",
197 Subsystem: "mvcc",
198 Name: "db_total_size_in_bytes",
199 Help: "Total size of the underlying database physically allocated in bytes.",
200 },
201 func() float64 {
202 reportDbTotalSizeInBytesDebugMu.RLock()
203 defer reportDbTotalSizeInBytesDebugMu.RUnlock()
204 return reportDbTotalSizeInBytesDebug()
205 },
206 )
207 // overridden by mvcc initialization
208 reportDbTotalSizeInBytesDebugMu sync.RWMutex
209 reportDbTotalSizeInBytesDebug = func() float64 { return 0 }
210
211 dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
212 Namespace: "etcd",
213 Subsystem: "mvcc",
214 Name: "db_total_size_in_use_in_bytes",
215 Help: "Total size of the underlying database logically in use in bytes.",
216 },
217 func() float64 {
218 reportDbTotalSizeInUseInBytesMu.RLock()
219 defer reportDbTotalSizeInUseInBytesMu.RUnlock()
220 return reportDbTotalSizeInUseInBytes()
221 },
222 )
223 // overridden by mvcc initialization
224 reportDbTotalSizeInUseInBytesMu sync.RWMutex
225 reportDbTotalSizeInUseInBytes = func() float64 { return 0 }
226
227 dbOpenReadTxN = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
228 Namespace: "etcd",
229 Subsystem: "mvcc",
230 Name: "db_open_read_transactions",
231 Help: "The number of currently open read transactions",
232 },
233
234 func() float64 {
235 reportDbOpenReadTxNMu.RLock()
236 defer reportDbOpenReadTxNMu.RUnlock()
237 return reportDbOpenReadTxN()
238 },
239 )
240 // overridden by mvcc initialization
241 reportDbOpenReadTxNMu sync.RWMutex
242 reportDbOpenReadTxN = func() float64 { return 0 }
243
244 hashSec = prometheus.NewHistogram(prometheus.HistogramOpts{
245 Namespace: "etcd",
246 Subsystem: "mvcc",
247 Name: "hash_duration_seconds",
248 Help: "The latency distribution of storage hash operation.",
249
250 // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms
251 // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2
252 // highest bucket start of 0.01 sec * 2^14 == 163.84 sec
253 Buckets: prometheus.ExponentialBuckets(.01, 2, 15),
254 })
255
256 hashRevSec = prometheus.NewHistogram(prometheus.HistogramOpts{
257 Namespace: "etcd",
258 Subsystem: "mvcc",
259 Name: "hash_rev_duration_seconds",
260 Help: "The latency distribution of storage hash by revision operation.",
261
262 // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms
263 // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2
264 // highest bucket start of 0.01 sec * 2^14 == 163.84 sec
265 Buckets: prometheus.ExponentialBuckets(.01, 2, 15),
266 })
267
268 currentRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
269 Namespace: "etcd_debugging",
270 Subsystem: "mvcc",
271 Name: "current_revision",
272 Help: "The current revision of store.",
273 },
274 func() float64 {
275 reportCurrentRevMu.RLock()
276 defer reportCurrentRevMu.RUnlock()
277 return reportCurrentRev()
278 },
279 )
280 // overridden by mvcc initialization
281 reportCurrentRevMu sync.RWMutex
282 reportCurrentRev = func() float64 { return 0 }
283
284 compactRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
285 Namespace: "etcd_debugging",
286 Subsystem: "mvcc",
287 Name: "compact_revision",
288 Help: "The revision of the last compaction in store.",
289 },
290 func() float64 {
291 reportCompactRevMu.RLock()
292 defer reportCompactRevMu.RUnlock()
293 return reportCompactRev()
294 },
295 )
296 // overridden by mvcc initialization
297 reportCompactRevMu sync.RWMutex
298 reportCompactRev = func() float64 { return 0 }
299)
300
301func init() {
302 prometheus.MustRegister(rangeCounter)
303 prometheus.MustRegister(rangeCounterDebug)
304 prometheus.MustRegister(putCounter)
305 prometheus.MustRegister(putCounterDebug)
306 prometheus.MustRegister(deleteCounter)
307 prometheus.MustRegister(deleteCounterDebug)
308 prometheus.MustRegister(txnCounter)
309 prometheus.MustRegister(txnCounterDebug)
310 prometheus.MustRegister(keysGauge)
311 prometheus.MustRegister(watchStreamGauge)
312 prometheus.MustRegister(watcherGauge)
313 prometheus.MustRegister(slowWatcherGauge)
314 prometheus.MustRegister(totalEventsCounter)
315 prometheus.MustRegister(pendingEventsGauge)
316 prometheus.MustRegister(indexCompactionPauseMs)
317 prometheus.MustRegister(dbCompactionPauseMs)
318 prometheus.MustRegister(dbCompactionTotalMs)
319 prometheus.MustRegister(dbCompactionKeysCounter)
320 prometheus.MustRegister(dbTotalSize)
321 prometheus.MustRegister(dbTotalSizeDebug)
322 prometheus.MustRegister(dbTotalSizeInUse)
323 prometheus.MustRegister(dbOpenReadTxN)
324 prometheus.MustRegister(hashSec)
325 prometheus.MustRegister(hashRevSec)
326 prometheus.MustRegister(currentRev)
327 prometheus.MustRegister(compactRev)
328}
329
330// ReportEventReceived reports that an event is received.
331// This function should be called when the external systems received an
332// event from mvcc.Watcher.
333func ReportEventReceived(n int) {
334 pendingEventsGauge.Sub(float64(n))
335 totalEventsCounter.Add(float64(n))
336}