github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/p2p/metrics.go (about)

     1  // Copyright 2021 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 p2p
    15  
    16  import (
    17  	grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
    18  	"github.com/prometheus/client_golang/prometheus"
    19  )
    20  
    21  const unknownPeerLabel = "unknown"
    22  
    23  var (
    24  	serverStreamCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    25  		Namespace: "ticdc",
    26  		Subsystem: "message_server",
    27  		Name:      "cur_stream_count",
    28  		Help:      "count of concurrent streams handled by the message server",
    29  	}, []string{"from"})
    30  
    31  	serverMessageCount = prometheus.NewCounterVec(prometheus.CounterOpts{
    32  		Namespace: "ticdc",
    33  		Subsystem: "message_server",
    34  		Name:      "message_count",
    35  		Help:      "count of messages received",
    36  	}, []string{"from"})
    37  
    38  	serverMessageBatchHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    39  		Namespace: "ticdc",
    40  		Subsystem: "message_server",
    41  		Name:      "message_batch_size",
    42  		Help:      "size in number of messages of message batches received",
    43  		Buckets:   prometheus.ExponentialBuckets(1, 2, 10),
    44  	}, []string{"from"})
    45  
    46  	// serverMessageBatchBytesHistogram records the wire sizes as reported by protobuf.
    47  	serverMessageBatchBytesHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    48  		Namespace: "ticdc",
    49  		Subsystem: "message_server",
    50  		Name:      "message_batch_bytes",
    51  		Help:      "size in bytes of message batches received",
    52  		Buckets:   prometheus.ExponentialBuckets(8.0, 2, 16),
    53  	}, []string{"from"})
    54  
    55  	// serverMessageBytesHistogram records the wire sizes as reported by protobuf.
    56  	serverMessageBytesHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    57  		Namespace: "ticdc",
    58  		Subsystem: "message_server",
    59  		Name:      "message_bytes",
    60  		Help:      "size in bytes of messages received",
    61  		Buckets:   prometheus.ExponentialBuckets(8.0, 2, 16),
    62  	}, []string{"from"})
    63  
    64  	serverAckCount = prometheus.NewCounterVec(prometheus.CounterOpts{
    65  		Namespace: "ticdc",
    66  		Subsystem: "message_server",
    67  		Name:      "ack_count",
    68  		Help:      "count of ack messages sent",
    69  	}, []string{"to"})
    70  
    71  	serverRepeatedMessageCount = prometheus.NewCounterVec(prometheus.CounterOpts{
    72  		Namespace: "ticdc",
    73  		Subsystem: "message_server",
    74  		Name:      "repeated_count",
    75  		Help:      "count of received repeated messages",
    76  	}, []string{"from", "topic"})
    77  
    78  	grpcClientMetrics = grpc_prometheus.NewClientMetrics(func(opts *prometheus.CounterOpts) {
    79  		opts.Namespace = "ticdc"
    80  		opts.Subsystem = "message_client"
    81  	})
    82  
    83  	clientCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    84  		Namespace: "ticdc",
    85  		Subsystem: "message_client",
    86  		Name:      "client_count",
    87  		Help:      "count of messaging clients",
    88  	}, []string{"to"})
    89  
    90  	clientMessageCount = prometheus.NewCounterVec(prometheus.CounterOpts{
    91  		Namespace: "ticdc",
    92  		Subsystem: "message_client",
    93  		Name:      "message_count",
    94  		Help:      "count of messages sent",
    95  	}, []string{"to"})
    96  
    97  	clientAckCount = prometheus.NewCounterVec(prometheus.CounterOpts{
    98  		Namespace: "ticdc",
    99  		Subsystem: "message_client",
   100  		Name:      "ack_count",
   101  		Help:      "count of ack messages received",
   102  	}, []string{"from"})
   103  )
   104  
   105  // InitMetrics initializes metrics used by pkg/p2p
   106  func InitMetrics(registry *prometheus.Registry) {
   107  	registry.MustRegister(serverStreamCount)
   108  	registry.MustRegister(serverMessageCount)
   109  	registry.MustRegister(serverMessageBatchHistogram)
   110  	registry.MustRegister(serverMessageBytesHistogram)
   111  	registry.MustRegister(serverMessageBatchBytesHistogram)
   112  	registry.MustRegister(serverAckCount)
   113  	registry.MustRegister(serverRepeatedMessageCount)
   114  	registry.MustRegister(grpcClientMetrics)
   115  	registry.MustRegister(clientCount)
   116  	registry.MustRegister(clientMessageCount)
   117  	registry.MustRegister(clientAckCount)
   118  }