github.com/matrixorigin/matrixone@v1.2.0/pkg/common/morpc/metrics.go (about)

     1  // Copyright 2021 - 2022 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 morpc
    16  
    17  import (
    18  	v2 "github.com/matrixorigin/matrixone/pkg/util/metric/v2"
    19  	"github.com/prometheus/client_golang/prometheus"
    20  )
    21  
    22  type metrics struct {
    23  	sendCounter                   prometheus.Counter
    24  	receiveCounter                prometheus.Counter
    25  	createCounter                 prometheus.Counter
    26  	closeCounter                  prometheus.Counter
    27  	connectCounter                prometheus.Counter
    28  	connectFailedCounter          prometheus.Counter
    29  	inputBytesCounter             prometheus.Counter
    30  	outputBytesCounter            prometheus.Counter
    31  	sendingQueueSizeGauge         prometheus.Gauge
    32  	sendingBatchSizeGauge         prometheus.Gauge
    33  	poolSizeGauge                 prometheus.Gauge
    34  	writeLatencyDurationHistogram prometheus.Observer
    35  	writeDurationHistogram        prometheus.Observer
    36  	connectDurationHistogram      prometheus.Observer
    37  	doneDurationHistogram         prometheus.Observer
    38  }
    39  
    40  func newMetrics(name string) *metrics {
    41  	return &metrics{
    42  		sendCounter:                   v2.NewRPCMessageSendCounterByName(name),
    43  		receiveCounter:                v2.NewRPCMessageReceiveCounterByName(name),
    44  		createCounter:                 v2.NewRPCBackendCreateCounterByName(name),
    45  		closeCounter:                  v2.NewRPCBackendCloseCounterByName(name),
    46  		connectCounter:                v2.NewRPCBackendConnectCounterByName(name),
    47  		connectFailedCounter:          v2.NewRPCBackendConnectFailedCounterByName(name),
    48  		poolSizeGauge:                 v2.NewRPCBackendPoolSizeGaugeByName(name),
    49  		sendingQueueSizeGauge:         v2.NewRPCBackendSendingQueueSizeGaugeByName(name),
    50  		sendingBatchSizeGauge:         v2.NewRPCBackendSendingBatchSizeGaugeByName(name),
    51  		writeDurationHistogram:        v2.NewRPCBackendWriteDurationHistogramByName(name),
    52  		connectDurationHistogram:      v2.NewRPCBackendConnectDurationHistogramByName(name),
    53  		doneDurationHistogram:         v2.NewRPCBackendDoneDurationHistogramByName(name),
    54  		writeLatencyDurationHistogram: v2.NewRPCBackendWriteLatencyDurationHistogramByName(name),
    55  		inputBytesCounter:             v2.NewRPCInputCounter(),
    56  		outputBytesCounter:            v2.NewRPCOutputCounter(),
    57  	}
    58  }
    59  
    60  type serverMetrics struct {
    61  	sendCounter                   prometheus.Counter
    62  	receiveCounter                prometheus.Counter
    63  	inputBytesCounter             prometheus.Counter
    64  	outputBytesCounter            prometheus.Counter
    65  	sendingQueueSizeGauge         prometheus.Gauge
    66  	sessionSizeGauge              prometheus.Gauge
    67  	sendingBatchSizeGauge         prometheus.Gauge
    68  	writeDurationHistogram        prometheus.Observer
    69  	writeLatencyDurationHistogram prometheus.Observer
    70  }
    71  
    72  func newServerMetrics(name string) *serverMetrics {
    73  	return &serverMetrics{
    74  		sendCounter:                   v2.NewRPCMessageSendCounterByName(name),
    75  		receiveCounter:                v2.NewRPCMessageReceiveCounterByName(name),
    76  		writeDurationHistogram:        v2.NewRPCServerWriteDurationHistogramByName(name),
    77  		sendingBatchSizeGauge:         v2.NewRPCServerSendingBatchSizeGaugeByName(name),
    78  		sendingQueueSizeGauge:         v2.NewRPCServerSendingQueueSizeGaugeByName(name),
    79  		writeLatencyDurationHistogram: v2.NewRPCServerWriteLatencyDurationHistogramByName(name),
    80  		sessionSizeGauge:              v2.NewRPCServerSessionSizeGaugeByName(name),
    81  		inputBytesCounter:             v2.NewRPCInputCounter(),
    82  		outputBytesCounter:            v2.NewRPCOutputCounter(),
    83  	}
    84  }