github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/v2/metrics.go (about) 1 // Copyright 2023 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package v2 16 17 import ( 18 "math" 19 20 "github.com/prometheus/client_golang/prometheus" 21 "github.com/prometheus/client_golang/prometheus/collectors" 22 ) 23 24 var ( 25 registry = prometheus.NewRegistry() 26 ) 27 28 func GetPrometheusRegistry() prometheus.Registerer { 29 return registry 30 } 31 32 func GetPrometheusGatherer() prometheus.Gatherer { 33 return registry 34 } 35 36 func init() { 37 registry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})) 38 registry.MustRegister(collectors.NewGoCollector( 39 collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsAll), 40 )) 41 42 initFileServiceMetrics() 43 initLogtailMetrics() 44 initTxnMetrics() 45 initTaskMetrics() 46 initRPCMetrics() 47 initMemMetrics() 48 initTraceMetrics() 49 initProxyMetrics() 50 initFrontendMetrics() 51 initPipelineMetrics() 52 53 registry.MustRegister(HeartbeatHistogram) 54 registry.MustRegister(HeartbeatFailureCounter) 55 registry.MustRegister(HeartbeatRecvHistogram) 56 registry.MustRegister(HeartbeatRecvFailureCounter) 57 } 58 59 func initMemMetrics() { 60 registry.MustRegister(memMPoolAllocatedSizeGauge) 61 registry.MustRegister(MemTotalCrossPoolFreeCounter) 62 registry.MustRegister(memMPoolHighWaterMarkGauge) 63 } 64 65 func initTaskMetrics() { 66 registry.MustRegister(taskShortDurationHistogram) 67 registry.MustRegister(taskLongDurationHistogram) 68 registry.MustRegister(taskBytesHistogram) 69 registry.MustRegister(taskCountHistogram) 70 71 registry.MustRegister(taskScheduledByCounter) 72 registry.MustRegister(taskGeneratedStuffCounter) 73 registry.MustRegister(taskSelectivityCounter) 74 75 registry.MustRegister(TaskMergeTransferPageLengthGauge) 76 77 registry.MustRegister(TaskStorageUsageCacheMemUsedGauge) 78 } 79 80 func initFileServiceMetrics() { 81 registry.MustRegister(fsReadCounter) 82 registry.MustRegister(S3ConnectCounter) 83 registry.MustRegister(S3DNSResolveCounter) 84 85 registry.MustRegister(s3IOBytesHistogram) 86 registry.MustRegister(s3IODurationHistogram) 87 registry.MustRegister(s3ConnDurationHistogram) 88 registry.MustRegister(localIOBytesHistogram) 89 registry.MustRegister(localIODurationHistogram) 90 91 registry.MustRegister(ioMergerCounter) 92 registry.MustRegister(ioMergerDuration) 93 } 94 95 func initLogtailMetrics() { 96 registry.MustRegister(LogtailLoadCheckpointCounter) 97 registry.MustRegister(logtailReceivedCounter) 98 99 registry.MustRegister(logTailQueueSizeGauge) 100 101 registry.MustRegister(LogTailBytesHistogram) 102 registry.MustRegister(logTailApplyDurationHistogram) 103 registry.MustRegister(logtailUpdatePartitionDurationHistogram) 104 registry.MustRegister(LogTailAppendDurationHistogram) 105 registry.MustRegister(logTailSendDurationHistogram) 106 registry.MustRegister(LogTailLoadCheckpointDurationHistogram) 107 108 registry.MustRegister(LogTailCollectDurationHistogram) 109 registry.MustRegister(LogTailSubscriptionCounter) 110 registry.MustRegister(txnTNSideDurationHistogram) 111 } 112 113 func initTxnMetrics() { 114 registry.MustRegister(txnCounter) 115 registry.MustRegister(txnStatementCounter) 116 registry.MustRegister(txnCommitCounter) 117 registry.MustRegister(TxnRollbackCounter) 118 registry.MustRegister(txnLockCounter) 119 120 registry.MustRegister(txnQueueSizeGauge) 121 122 registry.MustRegister(txnCommitDurationHistogram) 123 registry.MustRegister(TxnLifeCycleDurationHistogram) 124 registry.MustRegister(TxnLifeCycleStatementsTotalHistogram) 125 registry.MustRegister(txnCreateDurationHistogram) 126 registry.MustRegister(txnStatementDurationHistogram) 127 registry.MustRegister(txnLockDurationHistogram) 128 registry.MustRegister(txnUnlockDurationHistogram) 129 registry.MustRegister(TxnTableRangeDurationHistogram) 130 registry.MustRegister(TxnCheckPKDupDurationHistogram) 131 registry.MustRegister(TxnLockWaitersTotalHistogram) 132 registry.MustRegister(txnTableRangeSizeHistogram) 133 registry.MustRegister(txnMpoolDurationHistogram) 134 registry.MustRegister(TxnUnlockTableTotalHistogram) 135 registry.MustRegister(txnReaderDurationHistogram) 136 137 registry.MustRegister(TxnRangesLoadedObjectMetaTotalCounter) 138 registry.MustRegister(txnCNCommittedLocationQuantityGauge) 139 140 registry.MustRegister(txnRangesSelectivityHistogram) 141 } 142 143 func initRPCMetrics() { 144 registry.MustRegister(RPCClientCreateCounter) 145 registry.MustRegister(rpcBackendCreateCounter) 146 registry.MustRegister(rpcBackendClosedCounter) 147 registry.MustRegister(rpcBackendConnectCounter) 148 registry.MustRegister(rpcMessageCounter) 149 registry.MustRegister(rpcNetworkBytesCounter) 150 151 registry.MustRegister(rpcBackendPoolSizeGauge) 152 registry.MustRegister(rpcSendingQueueSizeGauge) 153 registry.MustRegister(rpcSendingBatchSizeGauge) 154 registry.MustRegister(rpcServerSessionSizeGauge) 155 156 registry.MustRegister(rpcBackendConnectDurationHistogram) 157 registry.MustRegister(rpcWriteDurationHistogram) 158 registry.MustRegister(rpcWriteLatencyDurationHistogram) 159 registry.MustRegister(rpcBackendDoneDurationHistogram) 160 161 } 162 163 func initTraceMetrics() { 164 registry.MustRegister(traceCollectorDurationHistogram) 165 registry.MustRegister(traceNegativeCUCounter) 166 } 167 168 func initProxyMetrics() { 169 registry.MustRegister(proxyConnectCounter) 170 registry.MustRegister(proxyDisconnectCounter) 171 registry.MustRegister(proxyTransferCounter) 172 registry.MustRegister(ProxyTransferDurationHistogram) 173 registry.MustRegister(ProxyDrainCounter) 174 registry.MustRegister(ProxyAvailableBackendServerNumGauge) 175 registry.MustRegister(ProxyTransferQueueSizeGauge) 176 registry.MustRegister(ProxyConnectionsNeedToTransferGauge) 177 } 178 179 func initFrontendMetrics() { 180 registry.MustRegister(acceptConnDurationHistogram) 181 registry.MustRegister(routineCounter) 182 registry.MustRegister(requestCounter) 183 } 184 185 func initPipelineMetrics() { 186 registry.MustRegister(PipelineServerDurationHistogram) 187 } 188 189 func getDurationBuckets() []float64 { 190 return append(prometheus.ExponentialBuckets(0.00001, 2, 30), math.MaxFloat64) 191 }