github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/v2/morpc.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 "github.com/prometheus/client_golang/prometheus" 19 ) 20 21 var ( 22 RPCClientCreateCounter = prometheus.NewCounterVec( 23 prometheus.CounterOpts{ 24 Namespace: "mo", 25 Subsystem: "rpc", 26 Name: "client_create_total", 27 Help: "Total number of morpc client created.", 28 }, []string{"name"}) 29 30 rpcMessageCounter = prometheus.NewCounterVec( 31 prometheus.CounterOpts{ 32 Namespace: "mo", 33 Subsystem: "rpc", 34 Name: "message_total", 35 Help: "Total number of morpc message transfer.", 36 }, []string{"name", "type"}) 37 38 rpcBackendCreateCounter = prometheus.NewCounterVec( 39 prometheus.CounterOpts{ 40 Namespace: "mo", 41 Subsystem: "rpc", 42 Name: "backend_create_total", 43 Help: "Total number of morpc backend created.", 44 }, []string{"name"}) 45 46 rpcBackendClosedCounter = prometheus.NewCounterVec( 47 prometheus.CounterOpts{ 48 Namespace: "mo", 49 Subsystem: "rpc", 50 Name: "backend_close_total", 51 Help: "Total number of morpc backend created.", 52 }, []string{"name"}) 53 54 rpcBackendConnectCounter = prometheus.NewCounterVec( 55 prometheus.CounterOpts{ 56 Namespace: "mo", 57 Subsystem: "rpc", 58 Name: "backend_connect_total", 59 Help: "Total number of morpc backend connect.", 60 }, []string{"name", "type"}) 61 62 rpcNetworkBytesCounter = prometheus.NewCounterVec( 63 prometheus.CounterOpts{ 64 Namespace: "mo", 65 Subsystem: "rpc", 66 Name: "network_bytes_total", 67 Help: "Total bytes of rpc network transfer.", 68 }, []string{"type"}) 69 ) 70 71 var ( 72 rpcBackendPoolSizeGauge = prometheus.NewGaugeVec( 73 prometheus.GaugeOpts{ 74 Namespace: "mo", 75 Subsystem: "rpc", 76 Name: "backend_pool_size", 77 Help: "Size of backend connection pool size.", 78 }, []string{"name"}) 79 80 rpcSendingQueueSizeGauge = prometheus.NewGaugeVec( 81 prometheus.GaugeOpts{ 82 Namespace: "mo", 83 Subsystem: "rpc", 84 Name: "sending_queue_size", 85 Help: "Size of sending queue size.", 86 }, []string{"name", "side"}) 87 88 rpcSendingBatchSizeGauge = prometheus.NewGaugeVec( 89 prometheus.GaugeOpts{ 90 Namespace: "mo", 91 Subsystem: "rpc", 92 Name: "sending_batch_size", 93 Help: "Size of sending batch size.", 94 }, []string{"name", "side"}) 95 96 rpcServerSessionSizeGauge = prometheus.NewGaugeVec( 97 prometheus.GaugeOpts{ 98 Namespace: "mo", 99 Subsystem: "rpc", 100 Name: "server_session_size", 101 Help: "Size of server sessions size.", 102 }, []string{"name"}) 103 ) 104 105 var ( 106 rpcBackendConnectDurationHistogram = prometheus.NewHistogramVec( 107 prometheus.HistogramOpts{ 108 Namespace: "mo", 109 Subsystem: "rpc", 110 Name: "backend_connect_duration_seconds", 111 Help: "Bucketed histogram of write data into socket duration.", 112 Buckets: getDurationBuckets(), 113 }, []string{"name"}) 114 115 rpcWriteDurationHistogram = prometheus.NewHistogramVec( 116 prometheus.HistogramOpts{ 117 Namespace: "mo", 118 Subsystem: "rpc", 119 Name: "write_duration_seconds", 120 Help: "Bucketed histogram of write data into socket duration.", 121 Buckets: getDurationBuckets(), 122 }, []string{"name", "side"}) 123 124 rpcWriteLatencyDurationHistogram = prometheus.NewHistogramVec( 125 prometheus.HistogramOpts{ 126 Namespace: "mo", 127 Subsystem: "rpc", 128 Name: "write_latency_duration_seconds", 129 Help: "Bucketed histogram of write latency duration.", 130 Buckets: getDurationBuckets(), 131 }, []string{"name", "side"}) 132 133 rpcBackendDoneDurationHistogram = prometheus.NewHistogramVec( 134 prometheus.HistogramOpts{ 135 Namespace: "mo", 136 Subsystem: "rpc", 137 Name: "backend_done_duration_seconds", 138 Help: "Bucketed histogram of request done duration.", 139 Buckets: getDurationBuckets(), 140 }, []string{"name"}) 141 ) 142 143 func NewRPCMessageSendCounterByName(name string) prometheus.Counter { 144 return rpcMessageCounter.WithLabelValues(name, "send") 145 } 146 147 func NewRPCMessageReceiveCounterByName(name string) prometheus.Counter { 148 return rpcMessageCounter.WithLabelValues(name, "receive") 149 } 150 151 func NewRPCBackendCreateCounterByName(name string) prometheus.Counter { 152 return rpcBackendCreateCounter.WithLabelValues(name) 153 } 154 155 func NewRPCBackendCloseCounterByName(name string) prometheus.Counter { 156 return rpcBackendClosedCounter.WithLabelValues(name) 157 } 158 159 func NewRPCBackendPoolSizeGaugeByName(name string) prometheus.Gauge { 160 return rpcBackendPoolSizeGauge.WithLabelValues(name) 161 } 162 163 func NewRPCBackendConnectCounterByName(name string) prometheus.Counter { 164 return rpcBackendConnectCounter.WithLabelValues(name, "total") 165 } 166 167 func NewRPCBackendConnectFailedCounterByName(name string) prometheus.Counter { 168 return rpcBackendConnectCounter.WithLabelValues(name, "failed") 169 } 170 171 func NewRPCBackendSendingQueueSizeGaugeByName(name string) prometheus.Gauge { 172 return rpcSendingQueueSizeGauge.WithLabelValues(name, "client") 173 } 174 175 func NewRPCServerSendingQueueSizeGaugeByName(name string) prometheus.Gauge { 176 return rpcSendingQueueSizeGauge.WithLabelValues(name, "server") 177 } 178 179 func NewRPCBackendSendingBatchSizeGaugeByName(name string) prometheus.Gauge { 180 return rpcSendingBatchSizeGauge.WithLabelValues(name, "client") 181 } 182 183 func NewRPCServerSendingBatchSizeGaugeByName(name string) prometheus.Gauge { 184 return rpcSendingBatchSizeGauge.WithLabelValues(name, "server") 185 } 186 187 func NewRPCBackendWriteDurationHistogramByName(name string) prometheus.Observer { 188 return rpcWriteDurationHistogram.WithLabelValues(name, "client") 189 } 190 191 func NewRPCServerWriteDurationHistogramByName(name string) prometheus.Observer { 192 return rpcWriteDurationHistogram.WithLabelValues(name, "server") 193 } 194 195 func NewRPCBackendWriteLatencyDurationHistogramByName(name string) prometheus.Observer { 196 return rpcWriteLatencyDurationHistogram.WithLabelValues(name, "client") 197 } 198 199 func NewRPCServerWriteLatencyDurationHistogramByName(name string) prometheus.Observer { 200 return rpcWriteLatencyDurationHistogram.WithLabelValues(name, "server") 201 } 202 203 func NewRPCBackendConnectDurationHistogramByName(name string) prometheus.Observer { 204 return rpcBackendConnectDurationHistogram.WithLabelValues(name) 205 } 206 207 func NewRPCBackendDoneDurationHistogramByName(name string) prometheus.Observer { 208 return rpcBackendDoneDurationHistogram.WithLabelValues(name) 209 } 210 211 func NewRPCServerSessionSizeGaugeByName(name string) prometheus.Gauge { 212 return rpcServerSessionSizeGauge.WithLabelValues(name) 213 } 214 215 func NewRPCInputCounter() prometheus.Counter { 216 return rpcNetworkBytesCounter.WithLabelValues("input") 217 } 218 219 func NewRPCOutputCounter() prometheus.Counter { 220 return rpcNetworkBytesCounter.WithLabelValues("output") 221 }