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