github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/syncer/metrics/validator_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 metrics 15 16 import ( 17 "github.com/pingcap/tiflow/engine/pkg/promutil" 18 "github.com/prometheus/client_golang/prometheus" 19 ) 20 21 var defaultFactory = &promutil.PromFactory{} 22 23 var ( 24 validatorErrorCount = defaultFactory.NewGaugeVec( 25 prometheus.GaugeOpts{ 26 Namespace: "dm", 27 Subsystem: "validator", 28 Name: "validator_error_count", 29 Help: "total number of validator errors", 30 }, []string{"task", "source_id"}) 31 32 validatorLogPosLatency = defaultFactory.NewGaugeVec( 33 prometheus.GaugeOpts{ 34 Namespace: "dm", 35 Subsystem: "validator", 36 Name: "validator_logpos_latency", 37 Help: "the log pos latency between validator and syncer", 38 }, []string{"task", "source_id"}) 39 validatorLogFileLatency = defaultFactory.NewGaugeVec( 40 prometheus.GaugeOpts{ 41 Namespace: "dm", 42 Subsystem: "validator", 43 Name: "validator_logfile_latency", 44 Help: "the log file latency between validator and syncer", 45 }, []string{"task", "source_id"}) 46 47 validatorBinlogPos = defaultFactory.NewGaugeVec( 48 prometheus.GaugeOpts{ 49 Namespace: "dm", 50 Subsystem: "validator", 51 Name: "validator_binlog_pos", 52 Help: "binlog position of the validator", 53 }, []string{"task", "source_id"}) 54 55 validatorBinlogFile = defaultFactory.NewGaugeVec( 56 prometheus.GaugeOpts{ 57 Namespace: "dm", 58 Subsystem: "validator", 59 Name: "validator_binlog_file", 60 Help: "current binlog file of the validator", 61 }, []string{"task", "source_id"}) 62 ) 63 64 func RegisterValidatorMetrics(registry *prometheus.Registry) { 65 registry.MustRegister(validatorErrorCount) 66 registry.MustRegister(validatorLogPosLatency) 67 registry.MustRegister(validatorLogFileLatency) 68 registry.MustRegister(validatorBinlogPos) 69 registry.MustRegister(validatorBinlogFile) 70 } 71 72 func RemoveValidatorLabelValuesWithTask(task string) { 73 validatorErrorCount.DeletePartialMatch(prometheus.Labels{"task": task}) 74 validatorLogPosLatency.DeletePartialMatch(prometheus.Labels{"task": task}) 75 validatorLogFileLatency.DeletePartialMatch(prometheus.Labels{"task": task}) 76 validatorBinlogPos.DeletePartialMatch(prometheus.Labels{"task": task}) 77 validatorBinlogFile.DeletePartialMatch(prometheus.Labels{"task": task}) 78 } 79 80 type ValidatorMetrics struct { 81 ErrorCount prometheus.Gauge 82 LogPosLatency prometheus.Gauge 83 LogFileLatency prometheus.Gauge 84 BinlogFile prometheus.Gauge 85 BinlogPos prometheus.Gauge 86 } 87 88 func NewValidatorMetrics(taskName, sourceID string) *ValidatorMetrics { 89 return &ValidatorMetrics{ 90 BinlogPos: validatorBinlogPos.WithLabelValues(taskName, sourceID), 91 BinlogFile: validatorBinlogFile.WithLabelValues(taskName, sourceID), 92 LogPosLatency: validatorLogPosLatency.WithLabelValues(taskName, sourceID), 93 LogFileLatency: validatorLogFileLatency.WithLabelValues(taskName, sourceID), 94 ErrorCount: validatorErrorCount.WithLabelValues(taskName, sourceID), 95 } 96 }