github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/metrics/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 metrics
    15  
    16  import (
    17  	"github.com/pingcap/tiflow/cdc/sink/metrics/cloudstorage"
    18  	"github.com/pingcap/tiflow/cdc/sink/metrics/mq"
    19  	"github.com/pingcap/tiflow/cdc/sink/metrics/tablesink"
    20  	"github.com/pingcap/tiflow/cdc/sink/metrics/txn"
    21  	"github.com/prometheus/client_golang/prometheus"
    22  )
    23  
    24  // rowSizeLowBound is set to 2K, only track data event with size not smaller than it.
    25  const largeRowSizeLowBound = 2 * 1024
    26  
    27  // ---------- Metrics used in Statistics. ---------- //
    28  var (
    29  	// ExecBatchHistogram records batch size of a txn.
    30  	ExecBatchHistogram = prometheus.NewHistogramVec(
    31  		prometheus.HistogramOpts{
    32  			Namespace: "ticdc",
    33  			Subsystem: "sink",
    34  			Name:      "batch_row_count",
    35  			Help:      "Row count number for a given batch.",
    36  			Buckets:   prometheus.ExponentialBuckets(1, 2, 18),
    37  		}, []string{"namespace", "changefeed", "type"}) // type is for `sinkType`
    38  
    39  	// ExecWriteBytesGauge records the total number of bytes written by sink.
    40  	TotalWriteBytesCounter = prometheus.NewCounterVec(
    41  		prometheus.CounterOpts{
    42  			Namespace: "ticdc",
    43  			Subsystem: "sink",
    44  			Name:      "write_bytes_total",
    45  			Help:      "Total number of bytes written by sink",
    46  		}, []string{"namespace", "changefeed", "type"}) // type is for `sinkType`
    47  
    48  	// LargeRowSizeHistogram records size of large rows.
    49  	LargeRowSizeHistogram = prometheus.NewHistogramVec(
    50  		prometheus.HistogramOpts{
    51  			Namespace: "ticdc",
    52  			Subsystem: "sink",
    53  			Name:      "large_row_size",
    54  			Help:      "The size of all received row changed events (in bytes).",
    55  			Buckets:   prometheus.ExponentialBuckets(largeRowSizeLowBound, 2, 15), // 2K~32M
    56  		}, []string{"namespace", "changefeed", "type"}) // type is for `sinkType`
    57  
    58  	// ExecDDLHistogram records the exexution time of a DDL.
    59  	ExecDDLHistogram = prometheus.NewHistogramVec(
    60  		prometheus.HistogramOpts{
    61  			Namespace: "ticdc",
    62  			Subsystem: "sink",
    63  			Name:      "ddl_exec_duration",
    64  			Help:      "Bucketed histogram of processing time (s) of a ddl.",
    65  			Buckets:   prometheus.ExponentialBuckets(0.01, 2, 18),
    66  		}, []string{"namespace", "changefeed", "type"}) // type is for `sinkType`
    67  
    68  	// ExecutionErrorCounter is the counter of execution errors.
    69  	ExecutionErrorCounter = prometheus.NewCounterVec(
    70  		prometheus.CounterOpts{
    71  			Namespace: "ticdc",
    72  			Subsystem: "sink",
    73  			Name:      "execution_error",
    74  			Help:      "Total count of execution errors.",
    75  		}, []string{"namespace", "changefeed", "type"}) // type is for `sinkType`
    76  )
    77  
    78  // InitMetrics registers all metrics in this file.
    79  func InitMetrics(registry *prometheus.Registry) {
    80  	registry.MustRegister(ExecBatchHistogram)
    81  	registry.MustRegister(TotalWriteBytesCounter)
    82  	registry.MustRegister(ExecDDLHistogram)
    83  	registry.MustRegister(LargeRowSizeHistogram)
    84  	registry.MustRegister(ExecutionErrorCounter)
    85  
    86  	tablesink.InitMetrics(registry)
    87  	txn.InitMetrics(registry)
    88  	mq.InitMetrics(registry)
    89  	cloudstorage.InitMetrics(registry)
    90  }