metrics.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2015 CoreOS, Inc.
  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/coreos/etcd/Godeps/_workspace/src/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",
  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",
  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",
  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",
  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",
  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",
  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",
  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. prometheus.MustRegister(readCounter)
  79. prometheus.MustRegister(writeCounter)
  80. prometheus.MustRegister(expireCounter)
  81. prometheus.MustRegister(watchRequests)
  82. prometheus.MustRegister(watcherCount)
  83. }
  84. func reportReadSuccess(read_action string) {
  85. readCounter.WithLabelValues(read_action).Inc()
  86. }
  87. func reportReadFailure(read_action string) {
  88. readCounter.WithLabelValues(read_action).Inc()
  89. readFailedCounter.WithLabelValues(read_action).Inc()
  90. }
  91. func reportWriteSuccess(write_action string) {
  92. writeCounter.WithLabelValues(write_action).Inc()
  93. }
  94. func reportWriteFailure(write_action string) {
  95. writeCounter.WithLabelValues(write_action).Inc()
  96. writeFailedCounter.WithLabelValues(write_action).Inc()
  97. }
  98. func reportExpiredKey() {
  99. expireCounter.Inc()
  100. }
  101. func reportWatchRequest() {
  102. watchRequests.Inc()
  103. }
  104. func reportWatcherAdded() {
  105. watcherCount.Inc()
  106. }
  107. func reportWatcherRemoved() {
  108. watcherCount.Dec()
  109. }