github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/processor/sourcemanager/sorter/metrics.go (about) 1 // Copyright 2023 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 sorter 15 16 import ( 17 "github.com/prometheus/client_golang/prometheus" 18 ) 19 20 var ( 21 mountWaitDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 22 Namespace: "ticdc", 23 Subsystem: "sorter", 24 Name: "mount_wait_duration", 25 Help: "Bucketed histogram of mount wait duration", 26 Buckets: prometheus.ExponentialBuckets(0.001, 2.0, 20), 27 }, []string{"namespace", "changefeed"}) 28 29 sorterWriteBytesHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 30 Namespace: "ticdc", 31 Subsystem: "sorter", 32 Name: "db_write_bytes", 33 Help: "Bucketed histogram of sorter write batch bytes", 34 Buckets: prometheus.ExponentialBuckets(16, 2.0, 20), 35 }, []string{"id"}) 36 37 sorterWriteDurationHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 38 Namespace: "ticdc", 39 Subsystem: "sorter", 40 Name: "db_write_duration_seconds", 41 Help: "Bucketed histogram of sorter write duration", 42 Buckets: prometheus.ExponentialBuckets(0.004, 2.0, 20), 43 }, []string{"id"}) 44 45 sorterCompactDurationHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 46 Namespace: "ticdc", 47 Subsystem: "sorter", 48 Name: "db_compact_duration_seconds", 49 Help: "Bucketed histogram of sorter manual compact duration", 50 Buckets: prometheus.ExponentialBuckets(0.004, 2.0, 20), 51 }, []string{"id"}) 52 53 sorterIterReadDurationHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 54 Namespace: "ticdc", 55 Subsystem: "sorter", 56 Name: "db_iter_read_duration_seconds", 57 Help: "Bucketed histogram of db sorter iterator read duration", 58 Buckets: prometheus.ExponentialBuckets(0.004, 2.0, 20), 59 }, []string{"namespace", "id", "call"}) 60 61 // inMemoryDataSizeGauge is the metric that records sorter memory usage. 62 inMemoryDataSizeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 63 Namespace: "ticdc", 64 Subsystem: "sorter", 65 Name: "in_memory_data_size_gauge", 66 Help: "The amount of pending data stored in-memory by the sorter", 67 }, []string{"id"}) 68 69 // onDiskDataSizeGauge is the metric that records sorter disk usage. 70 onDiskDataSizeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 71 Namespace: "ticdc", 72 Subsystem: "sorter", 73 Name: "on_disk_data_size_gauge", 74 Help: "The amount of pending data stored on-disk by the sorter", 75 }, []string{"id"}) 76 77 dbIteratorGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 78 Namespace: "ticdc", 79 Subsystem: "db", 80 Name: "iterator_count_gauge", 81 Help: "The number of iterator by the db", 82 }, []string{"id"}) 83 84 dbLevelCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 85 Namespace: "ticdc", 86 Subsystem: "db", 87 Name: "level_count", 88 Help: "The number of files in each level by the db", 89 }, []string{"level", "id"}) 90 91 dbWriteDelayCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 92 Namespace: "ticdc", 93 Subsystem: "db", 94 Name: "write_delay_total", 95 Help: "The total number of db delay", 96 }, []string{"id"}) 97 98 dbBlockCacheAccess = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 99 Namespace: "ticdc", 100 Subsystem: "db", 101 Name: "block_cache_access_total", 102 Help: "The total number of db block cache access", 103 }, []string{"id", "type"}) 104 105 dbRangeCleanCount = prometheus.NewCounter(prometheus.CounterOpts{ 106 Namespace: "ticdc", 107 Subsystem: "db", 108 Name: "range_clean_count", 109 Help: "The total number of db range clean", 110 }) 111 ) 112 113 /* Some metrics are shared in pipeline sorter and pull-based-sink sort engine */ 114 115 // CompactionDuration returns sorterCompactDurationHistogram. 116 func CompactionDuration() *prometheus.HistogramVec { 117 return sorterCompactDurationHistogram 118 } 119 120 // WriteDuration returns sorterWriteDurationHistogram. 121 func WriteDuration() *prometheus.HistogramVec { 122 return sorterWriteDurationHistogram 123 } 124 125 // WriteBytes returns sorterWriteBytesHistogram. 126 func WriteBytes() *prometheus.HistogramVec { 127 return sorterWriteBytesHistogram 128 } 129 130 // IterReadDuration returns sorterIterReadDurationHistogram. 131 func IterReadDuration() *prometheus.HistogramVec { 132 return sorterIterReadDurationHistogram 133 } 134 135 // InMemoryDataSize returns inMemoryDataSizeGauge. 136 func InMemoryDataSize() *prometheus.GaugeVec { 137 return inMemoryDataSizeGauge 138 } 139 140 // OnDiskDataSize returns onDiskDataSizeGauge. 141 func OnDiskDataSize() *prometheus.GaugeVec { 142 return onDiskDataSizeGauge 143 } 144 145 // IteratorGauge returns dbIteratorGauge. 146 func IteratorGauge() *prometheus.GaugeVec { 147 return dbIteratorGauge 148 } 149 150 // WriteDelayCount returns dbWriteDelayCount. 151 func WriteDelayCount() *prometheus.GaugeVec { 152 return dbWriteDelayCount 153 } 154 155 // LevelCount returns dbLevelCount. 156 func LevelCount() *prometheus.GaugeVec { 157 return dbLevelCount 158 } 159 160 // BlockCacheAccess returns dbBlockCacheAccess. 161 func BlockCacheAccess() *prometheus.GaugeVec { 162 return dbBlockCacheAccess 163 } 164 165 // RangeCleanCount returns dbRangeCleanCount. 166 func RangeCleanCount() prometheus.Counter { 167 return dbRangeCleanCount 168 } 169 170 // InitMetrics registers all metrics in this file 171 func InitMetrics(registry *prometheus.Registry) { 172 registry.MustRegister(mountWaitDuration) 173 registry.MustRegister(sorterWriteDurationHistogram) 174 registry.MustRegister(sorterCompactDurationHistogram) 175 registry.MustRegister(sorterWriteBytesHistogram) 176 registry.MustRegister(sorterIterReadDurationHistogram) 177 registry.MustRegister(inMemoryDataSizeGauge) 178 registry.MustRegister(onDiskDataSizeGauge) 179 registry.MustRegister(dbIteratorGauge) 180 181 // TODO: Seems these things belong to pebble instead of engine. 182 registry.MustRegister(dbLevelCount) 183 registry.MustRegister(dbWriteDelayCount) 184 registry.MustRegister(dbBlockCacheAccess) 185 registry.MustRegister(dbRangeCleanCount) 186 }