metrics.go 3.6 KB

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