github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/kv/metrics.go (about)

     1  // Copyright 2020 PingCAP, 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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package kv
    15  
    16  import (
    17  	grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
    18  	"github.com/prometheus/client_golang/prometheus"
    19  )
    20  
    21  var (
    22  	grpcMetrics = grpc_prometheus.NewClientMetrics()
    23  
    24  	eventFeedErrorCounter = prometheus.NewCounterVec(
    25  		prometheus.CounterOpts{
    26  			Namespace: "ticdc",
    27  			Subsystem: "kvclient",
    28  			Name:      "event_feed_error_count",
    29  			Help:      "The number of error return by tikv",
    30  		}, []string{"type"})
    31  	eventFeedGauge = prometheus.NewGauge(
    32  		prometheus.GaugeOpts{
    33  			Namespace: "ticdc",
    34  			Subsystem: "kvclient",
    35  			Name:      "event_feed_count",
    36  			Help:      "The number of event feed running",
    37  		})
    38  	scanRegionsDuration = prometheus.NewHistogramVec(
    39  		prometheus.HistogramOpts{
    40  			Namespace: "ticdc",
    41  			Subsystem: "kvclient",
    42  			Name:      "scan_regions_duration_seconds",
    43  			Help:      "The time it took to finish a scanRegions call.",
    44  			Buckets:   prometheus.ExponentialBuckets(0.001 /* 1 ms */, 2, 18),
    45  		}, []string{"capture"})
    46  	eventSize = prometheus.NewHistogramVec(
    47  		prometheus.HistogramOpts{
    48  			Namespace: "ticdc",
    49  			Subsystem: "kvclient",
    50  			Name:      "event_size_bytes",
    51  			Help:      "Size of KV events.",
    52  			Buckets:   prometheus.ExponentialBuckets(16, 2, 25),
    53  		}, []string{"capture", "type"})
    54  	pullEventCounter = prometheus.NewCounterVec(
    55  		prometheus.CounterOpts{
    56  			Namespace: "ticdc",
    57  			Subsystem: "kvclient",
    58  			Name:      "pull_event_count",
    59  			Help:      "event count received by this puller",
    60  		}, []string{"type", "capture", "changefeed"})
    61  	sendEventCounter = prometheus.NewCounterVec(
    62  		prometheus.CounterOpts{
    63  			Namespace: "ticdc",
    64  			Subsystem: "kvclient",
    65  			Name:      "send_event_count",
    66  			Help:      "event count sent to event channel by this puller",
    67  		}, []string{"type", "capture", "changefeed"})
    68  	clientChannelSize = prometheus.NewGaugeVec(
    69  		prometheus.GaugeOpts{
    70  			Namespace: "ticdc",
    71  			Subsystem: "kvclient",
    72  			Name:      "channel_size",
    73  			Help:      "size of each channel in kv client",
    74  		}, []string{"channel"})
    75  	clientRegionTokenSize = prometheus.NewGaugeVec(
    76  		prometheus.GaugeOpts{
    77  			Namespace: "ticdc",
    78  			Subsystem: "kvclient",
    79  			Name:      "region_token",
    80  			Help:      "size of region token in kv client",
    81  		}, []string{"store", "changefeed", "capture"})
    82  	batchResolvedEventSize = prometheus.NewHistogramVec(
    83  		prometheus.HistogramOpts{
    84  			Namespace: "ticdc",
    85  			Subsystem: "kvclient",
    86  			Name:      "batch_resolved_event_size",
    87  			Help:      "The number of region in one batch resolved ts event",
    88  			Buckets:   prometheus.ExponentialBuckets(2, 2, 16),
    89  		}, []string{"capture", "changefeed"})
    90  	etcdRequestCounter = prometheus.NewCounterVec(
    91  		prometheus.CounterOpts{
    92  			Namespace: "ticdc",
    93  			Subsystem: "etcd",
    94  			Name:      "request_count",
    95  			Help:      "request counter of etcd operation",
    96  		}, []string{"type", "capture"})
    97  	grpcPoolStreamGauge = prometheus.NewGaugeVec(
    98  		prometheus.GaugeOpts{
    99  			Namespace: "ticdc",
   100  			Subsystem: "kvclient",
   101  			Name:      "grpc_stream_count",
   102  			Help:      "active stream count of each gRPC connection",
   103  		}, []string{"store"})
   104  )
   105  
   106  // InitMetrics registers all metrics in the kv package
   107  func InitMetrics(registry *prometheus.Registry) {
   108  	registry.MustRegister(eventFeedErrorCounter)
   109  	registry.MustRegister(scanRegionsDuration)
   110  	registry.MustRegister(eventSize)
   111  	registry.MustRegister(eventFeedGauge)
   112  	registry.MustRegister(pullEventCounter)
   113  	registry.MustRegister(sendEventCounter)
   114  	registry.MustRegister(clientChannelSize)
   115  	registry.MustRegister(clientRegionTokenSize)
   116  	registry.MustRegister(batchResolvedEventSize)
   117  	registry.MustRegister(etcdRequestCounter)
   118  	registry.MustRegister(grpcPoolStreamGauge)
   119  
   120  	// Register client metrics to registry.
   121  	registry.MustRegister(grpcMetrics)
   122  }