metrics.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. "github.com/prometheus/client_golang/prometheus"
  17. )
  18. var (
  19. rangeCounter = prometheus.NewCounter(
  20. prometheus.CounterOpts{
  21. Namespace: "etcd_debugging",
  22. Subsystem: "mvcc",
  23. Name: "range_total",
  24. Help: "Total number of ranges seen by this member.",
  25. })
  26. putCounter = prometheus.NewCounter(
  27. prometheus.CounterOpts{
  28. Namespace: "etcd_debugging",
  29. Subsystem: "mvcc",
  30. Name: "put_total",
  31. Help: "Total number of puts seen by this member.",
  32. })
  33. deleteCounter = prometheus.NewCounter(
  34. prometheus.CounterOpts{
  35. Namespace: "etcd_debugging",
  36. Subsystem: "mvcc",
  37. Name: "delete_total",
  38. Help: "Total number of deletes seen by this member.",
  39. })
  40. txnCounter = prometheus.NewCounter(
  41. prometheus.CounterOpts{
  42. Namespace: "etcd_debugging",
  43. Subsystem: "mvcc",
  44. Name: "txn_total",
  45. Help: "Total number of txns seen by this member.",
  46. })
  47. keysGauge = prometheus.NewGauge(
  48. prometheus.GaugeOpts{
  49. Namespace: "etcd_debugging",
  50. Subsystem: "mvcc",
  51. Name: "keys_total",
  52. Help: "Total number of keys.",
  53. })
  54. watchStreamGauge = prometheus.NewGauge(
  55. prometheus.GaugeOpts{
  56. Namespace: "etcd_debugging",
  57. Subsystem: "mvcc",
  58. Name: "watch_stream_total",
  59. Help: "Total number of watch streams.",
  60. })
  61. watcherGauge = prometheus.NewGauge(
  62. prometheus.GaugeOpts{
  63. Namespace: "etcd_debugging",
  64. Subsystem: "mvcc",
  65. Name: "watcher_total",
  66. Help: "Total number of watchers.",
  67. })
  68. slowWatcherGauge = prometheus.NewGauge(
  69. prometheus.GaugeOpts{
  70. Namespace: "etcd_debugging",
  71. Subsystem: "mvcc",
  72. Name: "slow_watcher_total",
  73. Help: "Total number of unsynced slow watchers.",
  74. })
  75. totalEventsCounter = prometheus.NewCounter(
  76. prometheus.CounterOpts{
  77. Namespace: "etcd_debugging",
  78. Subsystem: "mvcc",
  79. Name: "events_total",
  80. Help: "Total number of events sent by this member.",
  81. })
  82. pendingEventsGauge = prometheus.NewGauge(
  83. prometheus.GaugeOpts{
  84. Namespace: "etcd_debugging",
  85. Subsystem: "mvcc",
  86. Name: "pending_events_total",
  87. Help: "Total number of pending events to be sent.",
  88. })
  89. indexCompactionPauseDurations = prometheus.NewHistogram(
  90. prometheus.HistogramOpts{
  91. Namespace: "etcd_debugging",
  92. Subsystem: "mvcc",
  93. Name: "index_compaction_pause_duration_milliseconds",
  94. Help: "Bucketed histogram of index compaction pause duration.",
  95. // 0.5ms -> 1second
  96. Buckets: prometheus.ExponentialBuckets(0.5, 2, 12),
  97. })
  98. dbCompactionPauseDurations = prometheus.NewHistogram(
  99. prometheus.HistogramOpts{
  100. Namespace: "etcd_debugging",
  101. Subsystem: "mvcc",
  102. Name: "db_compaction_pause_duration_milliseconds",
  103. Help: "Bucketed histogram of db compaction pause duration.",
  104. // 1ms -> 4second
  105. Buckets: prometheus.ExponentialBuckets(1, 2, 13),
  106. })
  107. dbCompactionTotalDurations = prometheus.NewHistogram(
  108. prometheus.HistogramOpts{
  109. Namespace: "etcd_debugging",
  110. Subsystem: "mvcc",
  111. Name: "db_compaction_total_duration_milliseconds",
  112. Help: "Bucketed histogram of db compaction total duration.",
  113. // 100ms -> 800second
  114. Buckets: prometheus.ExponentialBuckets(100, 2, 14),
  115. })
  116. dbTotalSize = prometheus.NewGauge(prometheus.GaugeOpts{
  117. Namespace: "etcd_debugging",
  118. Subsystem: "mvcc",
  119. Name: "db_total_size_in_bytes",
  120. Help: "Total size of the underlying database in bytes.",
  121. })
  122. )
  123. func init() {
  124. prometheus.MustRegister(rangeCounter)
  125. prometheus.MustRegister(putCounter)
  126. prometheus.MustRegister(deleteCounter)
  127. prometheus.MustRegister(txnCounter)
  128. prometheus.MustRegister(keysGauge)
  129. prometheus.MustRegister(watchStreamGauge)
  130. prometheus.MustRegister(watcherGauge)
  131. prometheus.MustRegister(slowWatcherGauge)
  132. prometheus.MustRegister(totalEventsCounter)
  133. prometheus.MustRegister(pendingEventsGauge)
  134. prometheus.MustRegister(indexCompactionPauseDurations)
  135. prometheus.MustRegister(dbCompactionPauseDurations)
  136. prometheus.MustRegister(dbCompactionTotalDurations)
  137. prometheus.MustRegister(dbTotalSize)
  138. }
  139. // ReportEventReceived reports that an event is received.
  140. // This function should be called when the external systems received an
  141. // event from mvcc.Watcher.
  142. func ReportEventReceived(n int) {
  143. pendingEventsGauge.Sub(float64(n))
  144. totalEventsCounter.Add(float64(n))
  145. }