metrics.go 8.4 KB

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