go.etcd.io/etcd@v3.3.27+incompatible/store/metrics.go (about)

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