github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/owner/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 owner
    15  
    16  import (
    17  	"time"
    18  
    19  	"github.com/pingcap/tiflow/cdc/metrics"
    20  	"github.com/prometheus/client_golang/prometheus"
    21  )
    22  
    23  var (
    24  	changefeedBarrierTsGauge = prometheus.NewGaugeVec(
    25  		prometheus.GaugeOpts{
    26  			Namespace: "ticdc",
    27  			Subsystem: "owner",
    28  			Name:      "barrier_ts",
    29  			Help:      "barrier ts of changefeeds",
    30  		}, []string{"namespace", "changefeed"})
    31  
    32  	changefeedCheckpointTsGauge = prometheus.NewGaugeVec(
    33  		prometheus.GaugeOpts{
    34  			Namespace: "ticdc",
    35  			Subsystem: "owner",
    36  			Name:      "checkpoint_ts",
    37  			Help:      "checkpoint ts of changefeeds",
    38  		}, []string{"namespace", "changefeed"})
    39  	changefeedCheckpointTsLagGauge = prometheus.NewGaugeVec(
    40  		prometheus.GaugeOpts{
    41  			Namespace: "ticdc",
    42  			Subsystem: "owner",
    43  			Name:      "checkpoint_ts_lag",
    44  			Help:      "checkpoint ts lag of changefeeds in seconds",
    45  		}, []string{"namespace", "changefeed"})
    46  	currentPDTsGauge = prometheus.NewGaugeVec(
    47  		prometheus.GaugeOpts{
    48  			Namespace: "ticdc",
    49  			Subsystem: "owner",
    50  			Name:      "current_pd_ts",
    51  			Help:      "The current PD ts",
    52  		}, []string{"namespace", "changefeed"})
    53  
    54  	changefeedCheckpointLagDuration = prometheus.NewHistogramVec(
    55  		prometheus.HistogramOpts{
    56  			Namespace: "ticdc",
    57  			Subsystem: "owner",
    58  			Name:      "checkpoint_lag_histogram",
    59  			Help:      "checkpoint lag histogram of changefeeds",
    60  			Buckets:   metrics.LagBucket(),
    61  		}, []string{"namespace", "changefeed"})
    62  
    63  	changefeedResolvedTsGauge = prometheus.NewGaugeVec(
    64  		prometheus.GaugeOpts{
    65  			Namespace: "ticdc",
    66  			Subsystem: "owner",
    67  			Name:      "resolved_ts",
    68  			Help:      "resolved ts of changefeeds",
    69  		}, []string{"namespace", "changefeed"})
    70  	changefeedResolvedTsLagGauge = prometheus.NewGaugeVec(
    71  		prometheus.GaugeOpts{
    72  			Namespace: "ticdc",
    73  			Subsystem: "owner",
    74  			Name:      "resolved_ts_lag",
    75  			Help:      "resolved ts lag of changefeeds in seconds",
    76  		}, []string{"namespace", "changefeed"})
    77  
    78  	changefeedResolvedTsLagDuration = prometheus.NewHistogramVec(
    79  		prometheus.HistogramOpts{
    80  			Namespace: "ticdc",
    81  			Subsystem: "owner",
    82  			Name:      "resolved_ts_lag_histogram",
    83  			Help:      "resolved_ts lag histogram of changefeeds",
    84  			Buckets:   metrics.LagBucket(),
    85  		}, []string{"namespace", "changefeed"})
    86  
    87  	ownershipCounter = prometheus.NewCounter(
    88  		prometheus.CounterOpts{
    89  			Namespace: "ticdc",
    90  			Subsystem: "owner",
    91  			Name:      "ownership_counter",
    92  			Help:      "The counter of ownership increases every 5 seconds on a owner capture",
    93  		})
    94  	changefeedStatusGauge = prometheus.NewGaugeVec(
    95  		prometheus.GaugeOpts{
    96  			Namespace: "ticdc",
    97  			Subsystem: "owner",
    98  			Name:      "status",
    99  			Help:      "The status of changefeeds",
   100  		}, []string{"namespace", "changefeed"})
   101  	changefeedTickDuration = prometheus.NewHistogramVec(
   102  		prometheus.HistogramOpts{
   103  			Namespace: "ticdc",
   104  			Subsystem: "owner",
   105  			Name:      "changefeed_tick_duration",
   106  			Help:      "Bucketed histogram of owner tick changefeed reactor time (s).",
   107  			Buckets:   prometheus.ExponentialBuckets(0.01 /* 10 ms */, 2, 18),
   108  		}, []string{"namespace", "changefeed"})
   109  	changefeedCloseDuration = prometheus.NewHistogram(
   110  		prometheus.HistogramOpts{
   111  			Namespace: "ticdc",
   112  			Subsystem: "owner",
   113  			Name:      "changefeed_close_duration",
   114  			Help:      "Bucketed histogram of owner close changefeed reactor time (s).",
   115  			Buckets:   prometheus.ExponentialBuckets(0.01 /* 10 ms */, 2, 18),
   116  		})
   117  	changefeedStartTimeGauge = prometheus.NewGaugeVec(
   118  		prometheus.GaugeOpts{
   119  			Namespace: "ticdc",
   120  			Subsystem: "owner",
   121  			Name:      "changefeed_start_time",
   122  			Help:      "The start time of changefeeds",
   123  		}, []string{"namespace", "changefeed", "type"})
   124  )
   125  
   126  const (
   127  	// When heavy operations (such as network IO and serialization) take too much time, the program
   128  	// should print a warning log, and if necessary, the timeout should be exposed externally through
   129  	// monitor.
   130  	changefeedLogsWarnDuration = 1 * time.Second
   131  
   132  	// TiDB collects metric data every 1 minute
   133  	downstreamObserverTickDuration = 30 * time.Second
   134  )
   135  
   136  // InitMetrics registers all metrics used in owner
   137  func InitMetrics(registry *prometheus.Registry) {
   138  	registry.MustRegister(changefeedBarrierTsGauge)
   139  
   140  	registry.MustRegister(changefeedCheckpointTsGauge)
   141  	registry.MustRegister(changefeedCheckpointTsLagGauge)
   142  	registry.MustRegister(changefeedCheckpointLagDuration)
   143  
   144  	registry.MustRegister(changefeedResolvedTsGauge)
   145  	registry.MustRegister(changefeedResolvedTsLagGauge)
   146  	registry.MustRegister(changefeedResolvedTsLagDuration)
   147  	registry.MustRegister(currentPDTsGauge)
   148  
   149  	registry.MustRegister(ownershipCounter)
   150  	registry.MustRegister(changefeedStatusGauge)
   151  	registry.MustRegister(changefeedTickDuration)
   152  	registry.MustRegister(changefeedCloseDuration)
   153  	registry.MustRegister(changefeedStartTimeGauge)
   154  }