...

Source file src/go.etcd.io/etcd/server/v3/mvcc/metrics.go

Documentation: go.etcd.io/etcd/server/v3/mvcc

     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 mvcc
    16  
    17  import (
    18  	"sync"
    19  
    20  	"github.com/prometheus/client_golang/prometheus"
    21  )
    22  
    23  var (
    24  	rangeCounter = prometheus.NewCounter(
    25  		prometheus.CounterOpts{
    26  			Namespace: "etcd",
    27  			Subsystem: "mvcc",
    28  			Name:      "range_total",
    29  			Help:      "Total number of ranges seen by this member.",
    30  		})
    31  	rangeCounterDebug = prometheus.NewCounter(
    32  		prometheus.CounterOpts{
    33  			Namespace: "etcd_debugging",
    34  			Subsystem: "mvcc",
    35  			Name:      "range_total",
    36  			Help:      "Total number of ranges seen by this member.",
    37  		})
    38  
    39  	putCounter = prometheus.NewCounter(
    40  		prometheus.CounterOpts{
    41  			Namespace: "etcd",
    42  			Subsystem: "mvcc",
    43  			Name:      "put_total",
    44  			Help:      "Total number of puts seen by this member.",
    45  		})
    46  
    47  	deleteCounter = prometheus.NewCounter(
    48  		prometheus.CounterOpts{
    49  			Namespace: "etcd",
    50  			Subsystem: "mvcc",
    51  			Name:      "delete_total",
    52  			Help:      "Total number of deletes seen by this member.",
    53  		})
    54  
    55  	txnCounter = prometheus.NewCounter(
    56  		prometheus.CounterOpts{
    57  			Namespace: "etcd",
    58  			Subsystem: "mvcc",
    59  			Name:      "txn_total",
    60  			Help:      "Total number of txns seen by this member.",
    61  		})
    62  
    63  	keysGauge = prometheus.NewGauge(
    64  		prometheus.GaugeOpts{
    65  			Namespace: "etcd_debugging",
    66  			Subsystem: "mvcc",
    67  			Name:      "keys_total",
    68  			Help:      "Total number of keys.",
    69  		})
    70  
    71  	watchStreamGauge = prometheus.NewGauge(
    72  		prometheus.GaugeOpts{
    73  			Namespace: "etcd_debugging",
    74  			Subsystem: "mvcc",
    75  			Name:      "watch_stream_total",
    76  			Help:      "Total number of watch streams.",
    77  		})
    78  
    79  	watcherGauge = prometheus.NewGauge(
    80  		prometheus.GaugeOpts{
    81  			Namespace: "etcd_debugging",
    82  			Subsystem: "mvcc",
    83  			Name:      "watcher_total",
    84  			Help:      "Total number of watchers.",
    85  		})
    86  
    87  	slowWatcherGauge = prometheus.NewGauge(
    88  		prometheus.GaugeOpts{
    89  			Namespace: "etcd_debugging",
    90  			Subsystem: "mvcc",
    91  			Name:      "slow_watcher_total",
    92  			Help:      "Total number of unsynced slow watchers.",
    93  		})
    94  
    95  	totalEventsCounter = prometheus.NewCounter(
    96  		prometheus.CounterOpts{
    97  			Namespace: "etcd_debugging",
    98  			Subsystem: "mvcc",
    99  			Name:      "events_total",
   100  			Help:      "Total number of events sent by this member.",
   101  		})
   102  
   103  	pendingEventsGauge = prometheus.NewGauge(
   104  		prometheus.GaugeOpts{
   105  			Namespace: "etcd_debugging",
   106  			Subsystem: "mvcc",
   107  			Name:      "pending_events_total",
   108  			Help:      "Total number of pending events to be sent.",
   109  		})
   110  
   111  	indexCompactionPauseMs = prometheus.NewHistogram(
   112  		prometheus.HistogramOpts{
   113  			Namespace: "etcd_debugging",
   114  			Subsystem: "mvcc",
   115  			Name:      "index_compaction_pause_duration_milliseconds",
   116  			Help:      "Bucketed histogram of index compaction pause duration.",
   117  
   118  			// lowest bucket start of upper bound 0.5 ms with factor 2
   119  			// highest bucket start of 0.5 ms * 2^13 == 4.096 sec
   120  			Buckets: prometheus.ExponentialBuckets(0.5, 2, 14),
   121  		})
   122  
   123  	dbCompactionPauseMs = prometheus.NewHistogram(
   124  		prometheus.HistogramOpts{
   125  			Namespace: "etcd_debugging",
   126  			Subsystem: "mvcc",
   127  			Name:      "db_compaction_pause_duration_milliseconds",
   128  			Help:      "Bucketed histogram of db compaction pause duration.",
   129  
   130  			// lowest bucket start of upper bound 1 ms with factor 2
   131  			// highest bucket start of 1 ms * 2^12 == 4.096 sec
   132  			Buckets: prometheus.ExponentialBuckets(1, 2, 13),
   133  		})
   134  
   135  	dbCompactionTotalMs = prometheus.NewHistogram(
   136  		prometheus.HistogramOpts{
   137  			Namespace: "etcd_debugging",
   138  			Subsystem: "mvcc",
   139  			Name:      "db_compaction_total_duration_milliseconds",
   140  			Help:      "Bucketed histogram of db compaction total duration.",
   141  
   142  			// lowest bucket start of upper bound 100 ms with factor 2
   143  			// highest bucket start of 100 ms * 2^13 == 8.192 sec
   144  			Buckets: prometheus.ExponentialBuckets(100, 2, 14),
   145  		})
   146  
   147  	dbCompactionLast = prometheus.NewGauge(
   148  		prometheus.GaugeOpts{
   149  			Namespace: "etcd_debugging",
   150  			Subsystem: "mvcc",
   151  			Name:      "db_compaction_last",
   152  			Help:      "The unix time of the last db compaction. Resets to 0 on start.",
   153  		})
   154  
   155  	dbCompactionKeysCounter = prometheus.NewCounter(
   156  		prometheus.CounterOpts{
   157  			Namespace: "etcd_debugging",
   158  			Subsystem: "mvcc",
   159  			Name:      "db_compaction_keys_total",
   160  			Help:      "Total number of db keys compacted.",
   161  		})
   162  
   163  	dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
   164  		Namespace: "etcd",
   165  		Subsystem: "mvcc",
   166  		Name:      "db_total_size_in_bytes",
   167  		Help:      "Total size of the underlying database physically allocated in bytes.",
   168  	},
   169  		func() float64 {
   170  			reportDbTotalSizeInBytesMu.RLock()
   171  			defer reportDbTotalSizeInBytesMu.RUnlock()
   172  			return reportDbTotalSizeInBytes()
   173  		},
   174  	)
   175  	// overridden by mvcc initialization
   176  	reportDbTotalSizeInBytesMu sync.RWMutex
   177  	reportDbTotalSizeInBytes   = func() float64 { return 0 }
   178  
   179  	// overridden by mvcc initialization
   180  	reportDbTotalSizeInBytesDebugMu sync.RWMutex
   181  	reportDbTotalSizeInBytesDebug   = func() float64 { return 0 }
   182  
   183  	dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
   184  		Namespace: "etcd",
   185  		Subsystem: "mvcc",
   186  		Name:      "db_total_size_in_use_in_bytes",
   187  		Help:      "Total size of the underlying database logically in use in bytes.",
   188  	},
   189  		func() float64 {
   190  			reportDbTotalSizeInUseInBytesMu.RLock()
   191  			defer reportDbTotalSizeInUseInBytesMu.RUnlock()
   192  			return reportDbTotalSizeInUseInBytes()
   193  		},
   194  	)
   195  	// overridden by mvcc initialization
   196  	reportDbTotalSizeInUseInBytesMu sync.RWMutex
   197  	reportDbTotalSizeInUseInBytes   = func() float64 { return 0 }
   198  
   199  	dbOpenReadTxN = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
   200  		Namespace: "etcd",
   201  		Subsystem: "mvcc",
   202  		Name:      "db_open_read_transactions",
   203  		Help:      "The number of currently open read transactions",
   204  	},
   205  
   206  		func() float64 {
   207  			reportDbOpenReadTxNMu.RLock()
   208  			defer reportDbOpenReadTxNMu.RUnlock()
   209  			return reportDbOpenReadTxN()
   210  		},
   211  	)
   212  	// overridden by mvcc initialization
   213  	reportDbOpenReadTxNMu sync.RWMutex
   214  	reportDbOpenReadTxN   = func() float64 { return 0 }
   215  
   216  	hashSec = prometheus.NewHistogram(prometheus.HistogramOpts{
   217  		Namespace: "etcd",
   218  		Subsystem: "mvcc",
   219  		Name:      "hash_duration_seconds",
   220  		Help:      "The latency distribution of storage hash operation.",
   221  
   222  		// 100 MB usually takes 100 ms, so start with 10 MB of 10 ms
   223  		// lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2
   224  		// highest bucket start of 0.01 sec * 2^14 == 163.84 sec
   225  		Buckets: prometheus.ExponentialBuckets(.01, 2, 15),
   226  	})
   227  
   228  	hashRevSec = prometheus.NewHistogram(prometheus.HistogramOpts{
   229  		Namespace: "etcd",
   230  		Subsystem: "mvcc",
   231  		Name:      "hash_rev_duration_seconds",
   232  		Help:      "The latency distribution of storage hash by revision operation.",
   233  
   234  		// 100 MB usually takes 100 ms, so start with 10 MB of 10 ms
   235  		// lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2
   236  		// highest bucket start of 0.01 sec * 2^14 == 163.84 sec
   237  		Buckets: prometheus.ExponentialBuckets(.01, 2, 15),
   238  	})
   239  
   240  	currentRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
   241  		Namespace: "etcd_debugging",
   242  		Subsystem: "mvcc",
   243  		Name:      "current_revision",
   244  		Help:      "The current revision of store.",
   245  	},
   246  		func() float64 {
   247  			reportCurrentRevMu.RLock()
   248  			defer reportCurrentRevMu.RUnlock()
   249  			return reportCurrentRev()
   250  		},
   251  	)
   252  	// overridden by mvcc initialization
   253  	reportCurrentRevMu sync.RWMutex
   254  	reportCurrentRev   = func() float64 { return 0 }
   255  
   256  	compactRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
   257  		Namespace: "etcd_debugging",
   258  		Subsystem: "mvcc",
   259  		Name:      "compact_revision",
   260  		Help:      "The revision of the last compaction in store.",
   261  	},
   262  		func() float64 {
   263  			reportCompactRevMu.RLock()
   264  			defer reportCompactRevMu.RUnlock()
   265  			return reportCompactRev()
   266  		},
   267  	)
   268  	// overridden by mvcc initialization
   269  	reportCompactRevMu sync.RWMutex
   270  	reportCompactRev   = func() float64 { return 0 }
   271  
   272  	totalPutSizeGauge = prometheus.NewGauge(
   273  		prometheus.GaugeOpts{
   274  			Namespace: "etcd_debugging",
   275  			Subsystem: "mvcc",
   276  			Name:      "total_put_size_in_bytes",
   277  			Help:      "The total size of put kv pairs seen by this member.",
   278  		})
   279  )
   280  
   281  func init() {
   282  	prometheus.MustRegister(rangeCounter)
   283  	prometheus.MustRegister(rangeCounterDebug)
   284  	prometheus.MustRegister(putCounter)
   285  	prometheus.MustRegister(deleteCounter)
   286  	prometheus.MustRegister(txnCounter)
   287  	prometheus.MustRegister(keysGauge)
   288  	prometheus.MustRegister(watchStreamGauge)
   289  	prometheus.MustRegister(watcherGauge)
   290  	prometheus.MustRegister(slowWatcherGauge)
   291  	prometheus.MustRegister(totalEventsCounter)
   292  	prometheus.MustRegister(pendingEventsGauge)
   293  	prometheus.MustRegister(indexCompactionPauseMs)
   294  	prometheus.MustRegister(dbCompactionPauseMs)
   295  	prometheus.MustRegister(dbCompactionTotalMs)
   296  	prometheus.MustRegister(dbCompactionLast)
   297  	prometheus.MustRegister(dbCompactionKeysCounter)
   298  	prometheus.MustRegister(dbTotalSize)
   299  	prometheus.MustRegister(dbTotalSizeInUse)
   300  	prometheus.MustRegister(dbOpenReadTxN)
   301  	prometheus.MustRegister(hashSec)
   302  	prometheus.MustRegister(hashRevSec)
   303  	prometheus.MustRegister(currentRev)
   304  	prometheus.MustRegister(compactRev)
   305  	prometheus.MustRegister(totalPutSizeGauge)
   306  }
   307  
   308  // ReportEventReceived reports that an event is received.
   309  // This function should be called when the external systems received an
   310  // event from mvcc.Watcher.
   311  func ReportEventReceived(n int) {
   312  	pendingEventsGauge.Sub(float64(n))
   313  	totalEventsCounter.Add(float64(n))
   314  }
   315  

View as plain text