metrics.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. dbTotalSizeDebugging = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
  118. Namespace: "etcd_debugging",
  119. Subsystem: "mvcc",
  120. Name: "db_total_size_in_bytes",
  121. Help: "Total size of the underlying database physically allocated in bytes. Use etcd_mvcc_db_total_size_in_bytes",
  122. },
  123. func() float64 {
  124. reportDbTotalSizeInBytesMu.RLock()
  125. defer reportDbTotalSizeInBytesMu.RUnlock()
  126. return reportDbTotalSizeInBytes()
  127. },
  128. )
  129. dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
  130. Namespace: "etcd",
  131. Subsystem: "mvcc",
  132. Name: "db_total_size_in_bytes",
  133. Help: "Total size of the underlying database physically allocated in bytes.",
  134. },
  135. func() float64 {
  136. reportDbTotalSizeInBytesMu.RLock()
  137. defer reportDbTotalSizeInBytesMu.RUnlock()
  138. return reportDbTotalSizeInBytes()
  139. },
  140. )
  141. // overridden by mvcc initialization
  142. reportDbTotalSizeInBytesMu sync.RWMutex
  143. reportDbTotalSizeInBytes = func() float64 { return 0 }
  144. dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
  145. Namespace: "etcd",
  146. Subsystem: "mvcc",
  147. Name: "db_total_size_in_use_in_bytes",
  148. Help: "Total size of the underlying database logically in use in bytes.",
  149. },
  150. func() float64 {
  151. reportDbTotalSizeInUseInBytesMu.RLock()
  152. defer reportDbTotalSizeInUseInBytesMu.RUnlock()
  153. return reportDbTotalSizeInUseInBytes()
  154. },
  155. )
  156. // overridden by mvcc initialization
  157. reportDbTotalSizeInUseInBytesMu sync.RWMutex
  158. reportDbTotalSizeInUseInBytes func() float64 = func() float64 { return 0 }
  159. hashDurations = prometheus.NewHistogram(prometheus.HistogramOpts{
  160. Namespace: "etcd",
  161. Subsystem: "mvcc",
  162. Name: "hash_duration_seconds",
  163. Help: "The latency distribution of storage hash operation.",
  164. // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms
  165. // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2
  166. // highest bucket start of 0.01 sec * 2^14 == 163.84 sec
  167. Buckets: prometheus.ExponentialBuckets(.01, 2, 15),
  168. })
  169. currentRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
  170. Namespace: "etcd_debugging",
  171. Subsystem: "mvcc",
  172. Name: "current_revision",
  173. Help: "The current revision of store.",
  174. },
  175. func() float64 {
  176. reportCurrentRevMu.RLock()
  177. defer reportCurrentRevMu.RUnlock()
  178. return reportCurrentRev()
  179. },
  180. )
  181. // overridden by mvcc initialization
  182. reportCurrentRevMu sync.RWMutex
  183. reportCurrentRev = func() float64 { return 0 }
  184. compactRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
  185. Namespace: "etcd_debugging",
  186. Subsystem: "mvcc",
  187. Name: "compact_revision",
  188. Help: "The revision of the last compaction in store.",
  189. },
  190. func() float64 {
  191. reportCompactRevMu.RLock()
  192. defer reportCompactRevMu.RUnlock()
  193. return reportCompactRev()
  194. },
  195. )
  196. // overridden by mvcc initialization
  197. reportCompactRevMu sync.RWMutex
  198. reportCompactRev = func() float64 { return 0 }
  199. )
  200. func init() {
  201. prometheus.MustRegister(rangeCounter)
  202. prometheus.MustRegister(putCounter)
  203. prometheus.MustRegister(deleteCounter)
  204. prometheus.MustRegister(txnCounter)
  205. prometheus.MustRegister(keysGauge)
  206. prometheus.MustRegister(watchStreamGauge)
  207. prometheus.MustRegister(watcherGauge)
  208. prometheus.MustRegister(slowWatcherGauge)
  209. prometheus.MustRegister(totalEventsCounter)
  210. prometheus.MustRegister(pendingEventsGauge)
  211. prometheus.MustRegister(indexCompactionPauseDurations)
  212. prometheus.MustRegister(dbCompactionPauseDurations)
  213. prometheus.MustRegister(dbCompactionTotalDurations)
  214. prometheus.MustRegister(dbTotalSizeDebugging)
  215. prometheus.MustRegister(dbTotalSize)
  216. prometheus.MustRegister(dbTotalSizeInUse)
  217. prometheus.MustRegister(hashDurations)
  218. prometheus.MustRegister(currentRev)
  219. prometheus.MustRegister(compactRev)
  220. }
  221. // ReportEventReceived reports that an event is received.
  222. // This function should be called when the external systems received an
  223. // event from mvcc.Watcher.
  224. func ReportEventReceived(n int) {
  225. pendingEventsGauge.Sub(float64(n))
  226. totalEventsCounter.Add(float64(n))
  227. }