metrics.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. dbTotalSize = 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.",
  129. },
  130. func() float64 {
  131. reportDbTotalSizeInBytesMu.RLock()
  132. defer reportDbTotalSizeInBytesMu.RUnlock()
  133. return reportDbTotalSizeInBytes()
  134. },
  135. )
  136. // overridden by mvcc initialization
  137. reportDbTotalSizeInBytesMu sync.RWMutex
  138. reportDbTotalSizeInBytes func() float64 = func() float64 { return 0 }
  139. dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
  140. Namespace: "etcd_debugging",
  141. Subsystem: "mvcc",
  142. Name: "db_total_size_in_use_in_bytes",
  143. Help: "Total size of the underlying database logically in use in bytes.",
  144. },
  145. func() float64 {
  146. reportDbTotalSizeInUseInBytesMu.RLock()
  147. defer reportDbTotalSizeInUseInBytesMu.RUnlock()
  148. return reportDbTotalSizeInUseInBytes()
  149. },
  150. )
  151. // overridden by mvcc initialization
  152. reportDbTotalSizeInUseInBytesMu sync.RWMutex
  153. reportDbTotalSizeInUseInBytes func() float64 = func() float64 { return 0 }
  154. )
  155. func init() {
  156. prometheus.MustRegister(rangeCounter)
  157. prometheus.MustRegister(putCounter)
  158. prometheus.MustRegister(deleteCounter)
  159. prometheus.MustRegister(txnCounter)
  160. prometheus.MustRegister(keysGauge)
  161. prometheus.MustRegister(watchStreamGauge)
  162. prometheus.MustRegister(watcherGauge)
  163. prometheus.MustRegister(slowWatcherGauge)
  164. prometheus.MustRegister(totalEventsCounter)
  165. prometheus.MustRegister(pendingEventsGauge)
  166. prometheus.MustRegister(indexCompactionPauseDurations)
  167. prometheus.MustRegister(dbCompactionPauseDurations)
  168. prometheus.MustRegister(dbCompactionTotalDurations)
  169. prometheus.MustRegister(dbCompactionKeysCounter)
  170. prometheus.MustRegister(dbTotalSize)
  171. prometheus.MustRegister(dbTotalSizeInUse)
  172. }
  173. // ReportEventReceived reports that an event is received.
  174. // This function should be called when the external systems received an
  175. // event from mvcc.Watcher.
  176. func ReportEventReceived(n int) {
  177. pendingEventsGauge.Sub(float64(n))
  178. totalEventsCounter.Add(float64(n))
  179. }