github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/metrics/mq/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 mq 15 16 import ( 17 "github.com/pingcap/tiflow/pkg/sink/codec" 18 "github.com/pingcap/tiflow/pkg/sink/kafka" 19 "github.com/pingcap/tiflow/pkg/sink/kafka/claimcheck" 20 "github.com/prometheus/client_golang/prometheus" 21 ) 22 23 var ( 24 // WorkerSendMessageDuration records the duration of flushing a group messages. 25 WorkerSendMessageDuration = prometheus.NewHistogramVec( 26 prometheus.HistogramOpts{ 27 Namespace: "ticdc", 28 Subsystem: "sink", 29 Name: "mq_worker_send_message_duration", 30 Help: "Send Message duration(s) for MQ worker.", 31 Buckets: prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms~524s 32 }, []string{"namespace", "changefeed"}) 33 // WorkerBatchSize record the size of each batched messages. 34 WorkerBatchSize = prometheus.NewHistogramVec( 35 prometheus.HistogramOpts{ 36 Namespace: "ticdc", 37 Subsystem: "sink", 38 Name: "mq_worker_batch_size", 39 Help: "Batch size for MQ worker.", 40 Buckets: prometheus.ExponentialBuckets(4, 2, 10), // 4 ~ 2048 41 }, []string{"namespace", "changefeed"}) 42 // WorkerBatchDuration record the time duration cost on batch messages. 43 WorkerBatchDuration = prometheus.NewHistogramVec( 44 prometheus.HistogramOpts{ 45 Namespace: "ticdc", 46 Subsystem: "sink", 47 Name: "mq_worker_batch_duration", 48 Help: "Batch duration for MQ worker.", 49 Buckets: prometheus.ExponentialBuckets(0.004, 2, 10), // 4ms ~ 2s 50 }, []string{"namespace", "changefeed"}) 51 ) 52 53 // InitMetrics registers all metrics in this file. 54 func InitMetrics(registry *prometheus.Registry) { 55 serverRegistry = registry 56 57 registry.MustRegister(WorkerSendMessageDuration) 58 registry.MustRegister(WorkerBatchSize) 59 registry.MustRegister(WorkerBatchDuration) 60 claimcheck.InitMetrics(registry) 61 codec.InitMetrics(registry) 62 kafka.InitMetrics(registry) 63 } 64 65 var serverRegistry *prometheus.Registry 66 67 // GetMetricRegistry for add pulsar default metrics 68 func GetMetricRegistry() *prometheus.Registry { 69 // make sure registry is not nil 70 if serverRegistry == nil { 71 serverRegistry = prometheus.DefaultRegisterer.(*prometheus.Registry) 72 } 73 return serverRegistry 74 }