metrics.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 v2store
  15. import "github.com/prometheus/client_golang/prometheus"
  16. // Set of raw Prometheus metrics.
  17. // Labels
  18. // * action = declared in event.go
  19. // * outcome = Outcome
  20. // Do not increment directly, use Report* methods.
  21. var (
  22. readCounter = prometheus.NewCounterVec(
  23. prometheus.CounterOpts{
  24. Namespace: "etcd_debugging",
  25. Subsystem: "store",
  26. Name: "reads_total",
  27. Help: "Total number of reads action by (get/getRecursive), local to this member.",
  28. }, []string{"action"})
  29. writeCounter = prometheus.NewCounterVec(
  30. prometheus.CounterOpts{
  31. Namespace: "etcd_debugging",
  32. Subsystem: "store",
  33. Name: "writes_total",
  34. Help: "Total number of writes (e.g. set/compareAndDelete) seen by this member.",
  35. }, []string{"action"})
  36. readFailedCounter = prometheus.NewCounterVec(
  37. prometheus.CounterOpts{
  38. Namespace: "etcd_debugging",
  39. Subsystem: "store",
  40. Name: "reads_failed_total",
  41. Help: "Failed read actions by (get/getRecursive), local to this member.",
  42. }, []string{"action"})
  43. writeFailedCounter = prometheus.NewCounterVec(
  44. prometheus.CounterOpts{
  45. Namespace: "etcd_debugging",
  46. Subsystem: "store",
  47. Name: "writes_failed_total",
  48. Help: "Failed write actions (e.g. set/compareAndDelete), seen by this member.",
  49. }, []string{"action"})
  50. expireCounter = prometheus.NewCounter(
  51. prometheus.CounterOpts{
  52. Namespace: "etcd_debugging",
  53. Subsystem: "store",
  54. Name: "expires_total",
  55. Help: "Total number of expired keys.",
  56. })
  57. watchRequests = prometheus.NewCounter(
  58. prometheus.CounterOpts{
  59. Namespace: "etcd_debugging",
  60. Subsystem: "store",
  61. Name: "watch_requests_total",
  62. Help: "Total number of incoming watch requests (new or reestablished).",
  63. })
  64. watcherCount = prometheus.NewGauge(
  65. prometheus.GaugeOpts{
  66. Namespace: "etcd_debugging",
  67. Subsystem: "store",
  68. Name: "watchers",
  69. Help: "Count of currently active watchers.",
  70. })
  71. )
  72. const (
  73. GetRecursive = "getRecursive"
  74. )
  75. func init() {
  76. if prometheus.Register(readCounter) != nil {
  77. // Tests will try to double register since the tests use both
  78. // store and store_test packages; ignore second attempts.
  79. return
  80. }
  81. prometheus.MustRegister(writeCounter)
  82. prometheus.MustRegister(expireCounter)
  83. prometheus.MustRegister(watchRequests)
  84. prometheus.MustRegister(watcherCount)
  85. }
  86. func reportReadSuccess(readAction string) {
  87. readCounter.WithLabelValues(readAction).Inc()
  88. }
  89. func reportReadFailure(readAction string) {
  90. readCounter.WithLabelValues(readAction).Inc()
  91. readFailedCounter.WithLabelValues(readAction).Inc()
  92. }
  93. func reportWriteSuccess(writeAction string) {
  94. writeCounter.WithLabelValues(writeAction).Inc()
  95. }
  96. func reportWriteFailure(writeAction string) {
  97. writeCounter.WithLabelValues(writeAction).Inc()
  98. writeFailedCounter.WithLabelValues(writeAction).Inc()
  99. }
  100. func reportExpiredKey() {
  101. expireCounter.Inc()
  102. }
  103. func reportWatchRequest() {
  104. watchRequests.Inc()
  105. }
  106. func reportWatcherAdded() {
  107. watcherCount.Inc()
  108. }
  109. func reportWatcherRemoved() {
  110. watcherCount.Dec()
  111. }