github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/metrics/txn/metrics.go (about)

     1  // Copyright 2022 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 txn
    15  
    16  import "github.com/prometheus/client_golang/prometheus"
    17  
    18  // ---------- Metrics for txn sink and backends. ---------- //
    19  var (
    20  	// ConflictDetectDuration records the duration of detecting conflict.
    21  	ConflictDetectDuration = prometheus.NewHistogramVec(
    22  		prometheus.HistogramOpts{
    23  			Namespace: "ticdc",
    24  			Subsystem: "sink",
    25  			Name:      "txn_conflict_detect_duration",
    26  			Help:      "Bucketed histogram of conflict detect time (s) for single DML statement.",
    27  			Buckets:   prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms~524s
    28  		}, []string{"namespace", "changefeed"})
    29  
    30  	// QueueDuration = ConflictDetectDuration + (queue time in txn workers).
    31  	QueueDuration = prometheus.NewHistogramVec(
    32  		prometheus.HistogramOpts{
    33  			Namespace: "ticdc",
    34  			Subsystem: "sink",
    35  			Name:      "txn_queue_duration",
    36  			Help:      "Bucketed histogram of queue time (s) for single DML statement.",
    37  			Buckets:   prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms~524s
    38  		}, []string{"namespace", "changefeed"})
    39  
    40  	WorkerFlushDuration = prometheus.NewHistogramVec(
    41  		prometheus.HistogramOpts{
    42  			Namespace: "ticdc",
    43  			Subsystem: "sink",
    44  			Name:      "txn_worker_flush_duration",
    45  			Help:      "Flush duration (s) for txn worker.",
    46  			Buckets:   prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms~524s
    47  		}, []string{"namespace", "changefeed", "id"})
    48  
    49  	WorkerTotalDuration = prometheus.NewHistogramVec(
    50  		prometheus.HistogramOpts{
    51  			Namespace: "ticdc",
    52  			Subsystem: "sink",
    53  			Name:      "txn_worker_total_duration",
    54  			Help:      "total duration (s) for txn worker.",
    55  			Buckets:   prometheus.ExponentialBuckets(0.0001, 2, 20), // 1ms~524s
    56  		}, []string{"namespace", "changefeed", "id"})
    57  
    58  	WorkerHandledRows = prometheus.NewCounterVec(
    59  		prometheus.CounterOpts{
    60  			Namespace: "ticdc",
    61  			Subsystem: "sink",
    62  			Name:      "txn_worker_handled_rows",
    63  			Help:      "Busy ratio (X ms in 1s) for all workers.",
    64  		}, []string{"namespace", "changefeed", "id"})
    65  
    66  	SinkDMLBatchCommit = prometheus.NewHistogramVec(
    67  		prometheus.HistogramOpts{
    68  			Namespace: "ticdc",
    69  			Subsystem: "sink",
    70  			Name:      "txn_sink_dml_batch_commit",
    71  			Help:      "Duration of committing a DML batch",
    72  			Buckets:   prometheus.ExponentialBuckets(0.01, 2, 18), // 10ms~1310s
    73  		}, []string{"namespace", "changefeed"})
    74  
    75  	SinkDMLBatchCallback = prometheus.NewHistogramVec(
    76  		prometheus.HistogramOpts{
    77  			Namespace: "ticdc",
    78  			Subsystem: "sink",
    79  			Name:      "txn_sink_dml_batch_callback",
    80  			Help:      "Duration of execuing a batch of callbacks",
    81  			Buckets:   prometheus.ExponentialBuckets(0.01, 2, 18), // 10ms~1300s
    82  		}, []string{"namespace", "changefeed"})
    83  
    84  	PrepareStatementErrors = prometheus.NewCounterVec(
    85  		prometheus.CounterOpts{
    86  			Namespace: "ticdc",
    87  			Subsystem: "sink",
    88  			Name:      "txn_prepare_statement_errors",
    89  			Help:      "Prepare statement errors",
    90  		}, []string{"namespace", "changefeed"})
    91  )
    92  
    93  // InitMetrics registers all metrics in this file.
    94  func InitMetrics(registry *prometheus.Registry) {
    95  	registry.MustRegister(ConflictDetectDuration)
    96  	registry.MustRegister(QueueDuration)
    97  	registry.MustRegister(WorkerFlushDuration)
    98  	registry.MustRegister(WorkerTotalDuration)
    99  	registry.MustRegister(WorkerHandledRows)
   100  	registry.MustRegister(SinkDMLBatchCommit)
   101  	registry.MustRegister(SinkDMLBatchCallback)
   102  	registry.MustRegister(PrepareStatementErrors)
   103  }