| 1 |
// 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 |
|
| 15 |
package mvcc |
| 16 |
|
| 17 |
import ( |
| 18 |
"sync" |
| 19 |
|
| 20 |
"github.com/prometheus/client_golang/prometheus" |
| 21 |
) |
| 22 |
|
| 23 |
var ( |
| 24 |
rangeCounter = prometheus.NewCounter( |
| 25 |
prometheus.CounterOpts{ |
| 26 |
Namespace: "etcd_debugging", |
| 27 |
Subsystem: "mvcc", |
| 28 |
Name: "range_total", |
| 29 |
Help: "Total number of ranges seen by this member.", |
| 30 |
}) |
| 31 |
|
| 32 |
putCounter = prometheus.NewCounter( |
| 33 |
prometheus.CounterOpts{ |
| 34 |
Namespace: "etcd_debugging", |
| 35 |
Subsystem: "mvcc", |
| 36 |
Name: "put_total", |
| 37 |
Help: "Total number of puts seen by this member.", |
| 38 |
}) |
| 39 |
|
| 40 |
deleteCounter = prometheus.NewCounter( |
| 41 |
prometheus.CounterOpts{ |
| 42 |
Namespace: "etcd_debugging", |
| 43 |
Subsystem: "mvcc", |
| 44 |
Name: "delete_total", |
| 45 |
Help: "Total number of deletes seen by this member.", |
| 46 |
}) |
| 47 |
|
| 48 |
txnCounter = prometheus.NewCounter( |
| 49 |
prometheus.CounterOpts{ |
| 50 |
Namespace: "etcd_debugging", |
| 51 |
Subsystem: "mvcc", |
| 52 |
Name: "txn_total", |
| 53 |
Help: "Total number of txns seen by this member.", |
| 54 |
}) |
| 55 |
|
| 56 |
keysGauge = prometheus.NewGauge( |
| 57 |
prometheus.GaugeOpts{ |
| 58 |
Namespace: "etcd_debugging", |
| 59 |
Subsystem: "mvcc", |
| 60 |
Name: "keys_total", |
| 61 |
Help: "Total number of keys.", |
| 62 |
}) |
| 63 |
|
| 64 |
watchStreamGauge = prometheus.NewGauge( |
| 65 |
prometheus.GaugeOpts{ |
| 66 |
Namespace: "etcd_debugging", |
| 67 |
Subsystem: "mvcc", |
| 68 |
Name: "watch_stream_total", |
| 69 |
Help: "Total number of watch streams.", |
| 70 |
}) |
| 71 |
|
| 72 |
watcherGauge = prometheus.NewGauge( |
| 73 |
prometheus.GaugeOpts{ |
| 74 |
Namespace: "etcd_debugging", |
| 75 |
Subsystem: "mvcc", |
| 76 |
Name: "watcher_total", |
| 77 |
Help: "Total number of watchers.", |
| 78 |
}) |
| 79 |
|
| 80 |
slowWatcherGauge = prometheus.NewGauge( |
| 81 |
prometheus.GaugeOpts{ |
| 82 |
Namespace: "etcd_debugging", |
| 83 |
Subsystem: "mvcc", |
| 84 |
Name: "slow_watcher_total", |
| 85 |
Help: "Total number of unsynced slow watchers.", |
| 86 |
}) |
| 87 |
|
| 88 |
totalEventsCounter = prometheus.NewCounter( |
| 89 |
prometheus.CounterOpts{ |
| 90 |
Namespace: "etcd_debugging", |
| 91 |
Subsystem: "mvcc", |
| 92 |
Name: "events_total", |
| 93 |
Help: "Total number of events sent by this member.", |
| 94 |
}) |
| 95 |
|
| 96 |
pendingEventsGauge = prometheus.NewGauge( |
| 97 |
prometheus.GaugeOpts{ |
| 98 |
Namespace: "etcd_debugging", |
| 99 |
Subsystem: "mvcc", |
| 100 |
Name: "pending_events_total", |
| 101 |
Help: "Total number of pending events to be sent.", |
| 102 |
}) |
| 103 |
|
| 104 |
indexCompactionPauseDurations = prometheus.NewHistogram( |
| 105 |
prometheus.HistogramOpts{ |
| 106 |
Namespace: "etcd_debugging", |
| 107 |
Subsystem: "mvcc", |
| 108 |
Name: "index_compaction_pause_duration_milliseconds", |
| 109 |
Help: "Bucketed histogram of index compaction pause duration.", |
| 110 |
// 0.5ms -> 1second |
| 111 |
Buckets: prometheus.ExponentialBuckets(0.5, 2, 12), |
| 112 |
}) |
| 113 |
|
| 114 |
dbCompactionPauseDurations = prometheus.NewHistogram( |
| 115 |
prometheus.HistogramOpts{ |
| 116 |
Namespace: "etcd_debugging", |
| 117 |
Subsystem: "mvcc", |
| 118 |
Name: "db_compaction_pause_duration_milliseconds", |
| 119 |
Help: "Bucketed histogram of db compaction pause duration.", |
| 120 |
// 1ms -> 4second |
| 121 |
Buckets: prometheus.ExponentialBuckets(1, 2, 13), |
| 122 |
}) |
| 123 |
|
| 124 |
dbCompactionTotalDurations = prometheus.NewHistogram( |
| 125 |
prometheus.HistogramOpts{ |
| 126 |
Namespace: "etcd_debugging", |
| 127 |
Subsystem: "mvcc", |
| 128 |
Name: "db_compaction_total_duration_milliseconds", |
| 129 |
Help: "Bucketed histogram of db compaction total duration.", |
| 130 |
// 100ms -> 800second |
| 131 |
Buckets: prometheus.ExponentialBuckets(100, 2, 14), |
| 132 |
}) |
| 133 |
|
| 134 |
dbCompactionKeysCounter = prometheus.NewCounter( |
| 135 |
prometheus.CounterOpts{ |
| 136 |
Namespace: "etcd_debugging", |
| 137 |
Subsystem: "mvcc", |
| 138 |
Name: "db_compaction_keys_total", |
| 139 |
Help: "Total number of db keys compacted.", |
| 140 |
}) |
| 141 |
|
| 142 |
dbTotalSizeDebugging = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ |
| 143 |
Namespace: "etcd_debugging", |
| 144 |
Subsystem: "mvcc", |
| 145 |
Name: "db_total_size_in_bytes", |
| 146 |
Help: "Total size of the underlying database physically allocated in bytes. Use etcd_mvcc_db_total_size_in_bytes", |
| 147 |
}, |
| 148 |
func() float64 { |
| 149 |
reportDbTotalSizeInBytesMu.RLock() |
| 150 |
defer reportDbTotalSizeInBytesMu.RUnlock() |
| 151 |
return reportDbTotalSizeInBytes() |
| 152 |
}, |
| 153 |
) |
| 154 |
dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ |
| 155 |
Namespace: "etcd", |
| 156 |
Subsystem: "mvcc", |
| 157 |
Name: "db_total_size_in_bytes", |
| 158 |
Help: "Total size of the underlying database physically allocated in bytes.", |
| 159 |
}, |
| 160 |
func() float64 { |
| 161 |
reportDbTotalSizeInBytesMu.RLock() |
| 162 |
defer reportDbTotalSizeInBytesMu.RUnlock() |
| 163 |
return reportDbTotalSizeInBytes() |
| 164 |
}, |
| 165 |
) |
| 166 |
// overridden by mvcc initialization |
| 167 |
reportDbTotalSizeInBytesMu sync.RWMutex |
| 168 |
reportDbTotalSizeInBytes = func() float64 { return 0 } |
| 169 |
|
| 170 |
dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ |
| 171 |
Namespace: "etcd", |
| 172 |
Subsystem: "mvcc", |
| 173 |
Name: "db_total_size_in_use_in_bytes", |
| 174 |
Help: "Total size of the underlying database logically in use in bytes.", |
| 175 |
}, |
| 176 |
func() float64 { |
| 177 |
reportDbTotalSizeInUseInBytesMu.RLock() |
| 178 |
defer reportDbTotalSizeInUseInBytesMu.RUnlock() |
| 179 |
return reportDbTotalSizeInUseInBytes() |
| 180 |
}, |
| 181 |
) |
| 182 |
// overridden by mvcc initialization |
| 183 |
reportDbTotalSizeInUseInBytesMu sync.RWMutex |
| 184 |
reportDbTotalSizeInUseInBytes func() float64 = func() float64 { return 0 } |
| 185 |
|
| 186 |
hashDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ |
| 187 |
Namespace: "etcd", |
| 188 |
Subsystem: "mvcc", |
| 189 |
Name: "hash_duration_seconds", |
| 190 |
Help: "The latency distribution of storage hash operation.", |
| 191 |
|
| 192 |
// 100 MB usually takes 100 ms, so start with 10 MB of 10 ms |
| 193 |
// lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 |
| 194 |
// highest bucket start of 0.01 sec * 2^14 == 163.84 sec |
| 195 |
Buckets: prometheus.ExponentialBuckets(.01, 2, 15), |
| 196 |
}) |
| 197 |
|
| 198 |
hashRevDurations = prometheus.NewHistogram(prometheus.HistogramOpts{ |
| 199 |
Namespace: "etcd", |
| 200 |
Subsystem: "mvcc", |
| 201 |
Name: "hash_rev_duration_seconds", |
| 202 |
Help: "The latency distribution of storage hash by revision operation.", |
| 203 |
|
| 204 |
// 100 MB usually takes 100 ms, so start with 10 MB of 10 ms |
| 205 |
// lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 |
| 206 |
// highest bucket start of 0.01 sec * 2^14 == 163.84 sec |
| 207 |
Buckets: prometheus.ExponentialBuckets(.01, 2, 15), |
| 208 |
}) |
| 209 |
) |
| 210 |
|
| 211 |
func init() { |
| 212 |
prometheus.MustRegister(rangeCounter) |
| 213 |
prometheus.MustRegister(putCounter) |
| 214 |
prometheus.MustRegister(deleteCounter) |
| 215 |
prometheus.MustRegister(txnCounter) |
| 216 |
prometheus.MustRegister(keysGauge) |
| 217 |
prometheus.MustRegister(watchStreamGauge) |
| 218 |
prometheus.MustRegister(watcherGauge) |
| 219 |
prometheus.MustRegister(slowWatcherGauge) |
| 220 |
prometheus.MustRegister(totalEventsCounter) |
| 221 |
prometheus.MustRegister(pendingEventsGauge) |
| 222 |
prometheus.MustRegister(indexCompactionPauseDurations) |
| 223 |
prometheus.MustRegister(dbCompactionPauseDurations) |
| 224 |
prometheus.MustRegister(dbCompactionTotalDurations) |
| 225 |
prometheus.MustRegister(dbCompactionKeysCounter) |
| 226 |
prometheus.MustRegister(dbTotalSizeDebugging) |
| 227 |
prometheus.MustRegister(dbTotalSize) |
| 228 |
prometheus.MustRegister(dbTotalSizeInUse) |
| 229 |
prometheus.MustRegister(hashDurations) |
| 230 |
prometheus.MustRegister(hashRevDurations) |
| 231 |
} |
| 232 |
|
| 233 |
// ReportEventReceived reports that an event is received. |
| 234 |
// This function should be called when the external systems received an |
| 235 |
// event from mvcc.Watcher. |
| 236 |
func ReportEventReceived(n int) { |
| 237 |
pendingEventsGauge.Sub(float64(n)) |
| 238 |
totalEventsCounter.Add(float64(n)) |
| 239 |
} |