dubbo.apache.org/dubbo-go/v3@v3.1.1/metrics/rpc/metric_set.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package rpc
    19  
    20  import (
    21  	"dubbo.apache.org/dubbo-go/v3/metrics"
    22  )
    23  
    24  // metricSet is the metric set for rpc
    25  type metricSet struct {
    26  	provider *providerMetrics
    27  	consumer *consumerMetrics
    28  }
    29  
    30  type providerMetrics struct {
    31  	rpcCommonMetrics
    32  }
    33  
    34  type consumerMetrics struct {
    35  	rpcCommonMetrics
    36  }
    37  
    38  // rpcCommonMetrics is the common metrics for both provider and consumer
    39  type rpcCommonMetrics struct {
    40  	qpsTotal                      metrics.QpsMetricVec
    41  	requestsTotal                 metrics.CounterVec
    42  	requestsTotalAggregate        metrics.AggregateCounterVec
    43  	requestsProcessingTotal       metrics.GaugeVec
    44  	requestsSucceedTotal          metrics.CounterVec
    45  	requestsSucceedTotalAggregate metrics.AggregateCounterVec
    46  	requestsFailedTotal           metrics.CounterVec
    47  	requestsFailedTotalAggregate  metrics.AggregateCounterVec
    48  	rtMilliseconds                metrics.RtVec
    49  	rtMillisecondsQuantiles       metrics.QuantileMetricVec
    50  	rtMillisecondsAggregate       metrics.RtVec
    51  }
    52  
    53  // buildMetricSet will call init functions to initialize the metricSet
    54  func buildMetricSet(registry metrics.MetricRegistry) *metricSet {
    55  	ms := &metricSet{
    56  		provider: &providerMetrics{},
    57  		consumer: &consumerMetrics{},
    58  	}
    59  	ms.provider.init(registry)
    60  	ms.consumer.init(registry)
    61  	return ms
    62  }
    63  
    64  func (pm *providerMetrics) init(registry metrics.MetricRegistry) {
    65  	pm.qpsTotal = metrics.NewQpsMetricVec(registry, metrics.NewMetricKey("dubbo_provider_qps_total", "The number of requests received by the provider per second"))
    66  	pm.requestsTotal = metrics.NewCounterVec(registry, metrics.NewMetricKey("dubbo_provider_requests_total", "The total number of received requests by the provider"))
    67  	pm.requestsTotalAggregate = metrics.NewAggregateCounterVec(registry, metrics.NewMetricKey("dubbo_provider_requests_total_aggregate", "The total number of received requests by the provider under the sliding window"))
    68  	pm.requestsProcessingTotal = metrics.NewGaugeVec(registry, metrics.NewMetricKey("dubbo_provider_requests_processing_total", "The number of received requests being processed by the provider"))
    69  	pm.requestsSucceedTotal = metrics.NewCounterVec(registry, metrics.NewMetricKey("dubbo_provider_requests_succeed_total", "The number of requests successfully received by the provider"))
    70  	pm.requestsSucceedTotalAggregate = metrics.NewAggregateCounterVec(registry, metrics.NewMetricKey("dubbo_provider_requests_succeed_total_aggregate", "The number of successful requests received by the provider under the sliding window"))
    71  	pm.requestsFailedTotal = metrics.NewCounterVec(registry, metrics.NewMetricKey("dubbo_provider_requests_failed_total", "Total Failed Requests"))
    72  	pm.requestsFailedTotalAggregate = metrics.NewAggregateCounterVec(registry, metrics.NewMetricKey("dubbo_provider_requests_failed_total_aggregate", "Total Failed Aggregate Requests"))
    73  	pm.rtMilliseconds = metrics.NewRtVec(registry,
    74  		metrics.NewMetricKey("dubbo_provider_rt_milliseconds", "response time among all requests processed by the provider"),
    75  		&metrics.RtOpts{Aggregate: false},
    76  	)
    77  	pm.rtMillisecondsAggregate = metrics.NewRtVec(registry,
    78  		metrics.NewMetricKey("dubbo_provider_rt", "response time of the provider under the sliding window"),
    79  		&metrics.RtOpts{Aggregate: true, BucketNum: metrics.DefaultBucketNum, TimeWindowSeconds: metrics.DefaultTimeWindowSeconds},
    80  	)
    81  	pm.rtMillisecondsQuantiles = metrics.NewQuantileMetricVec(registry, []*metrics.MetricKey{
    82  		metrics.NewMetricKey("dubbo_provider_rt_milliseconds_p50", "The total response time spent by providers processing 50% of requests"),
    83  		metrics.NewMetricKey("dubbo_provider_rt_milliseconds_p90", "The total response time spent by providers processing 90% of requests"),
    84  		metrics.NewMetricKey("dubbo_provider_rt_milliseconds_p95", "The total response time spent by providers processing 95% of requests"),
    85  		metrics.NewMetricKey("dubbo_provider_rt_milliseconds_p99", "The total response time spent by providers processing 99% of requests"),
    86  	}, []float64{0.5, 0.9, 0.95, 0.99})
    87  }
    88  
    89  func (cm *consumerMetrics) init(registry metrics.MetricRegistry) {
    90  	cm.qpsTotal = metrics.NewQpsMetricVec(registry, metrics.NewMetricKey("dubbo_consumer_qps_total", "The number of requests sent by consumers per second"))
    91  	cm.requestsTotal = metrics.NewCounterVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_total", "The total number of requests sent by consumers"))
    92  	cm.requestsTotalAggregate = metrics.NewAggregateCounterVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_total_aggregate", "The total number of requests sent by consumers under the sliding window"))
    93  	cm.requestsProcessingTotal = metrics.NewGaugeVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_processing_total", "The number of received requests being processed by the consumer"))
    94  	cm.requestsSucceedTotal = metrics.NewCounterVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_succeed_total", "The number of successful requests sent by consumers"))
    95  	cm.requestsSucceedTotalAggregate = metrics.NewAggregateCounterVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_succeed_total_aggregate", "The number of successful requests sent by consumers under the sliding window"))
    96  	cm.requestsFailedTotal = metrics.NewCounterVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_failed_total", "Total Failed Requests"))
    97  	cm.requestsFailedTotalAggregate = metrics.NewAggregateCounterVec(registry, metrics.NewMetricKey("dubbo_consumer_requests_failed_total_aggregate", "Total Failed Aggregate Requests"))
    98  	cm.rtMilliseconds = metrics.NewRtVec(registry,
    99  		metrics.NewMetricKey("dubbo_consumer_rt_milliseconds", "response time among all requests from consumers"),
   100  		&metrics.RtOpts{Aggregate: false},
   101  	)
   102  	cm.rtMillisecondsAggregate = metrics.NewRtVec(registry,
   103  		metrics.NewMetricKey("dubbo_consumer_rt", "response time of the consumer under the sliding window"),
   104  		&metrics.RtOpts{Aggregate: true, BucketNum: metrics.DefaultBucketNum, TimeWindowSeconds: metrics.DefaultTimeWindowSeconds},
   105  	)
   106  	cm.rtMillisecondsQuantiles = metrics.NewQuantileMetricVec(registry, []*metrics.MetricKey{
   107  		metrics.NewMetricKey("dubbo_consumer_rt_milliseconds_p50", "The total response time spent by consumers processing 50% of requests"),
   108  		metrics.NewMetricKey("dubbo_consumer_rt_milliseconds_p90", "The total response time spent by consumers processing 90% of requests"),
   109  		metrics.NewMetricKey("dubbo_consumer_rt_milliseconds_p95", "The total response time spent by consumers processing 95% of requests"),
   110  		metrics.NewMetricKey("dubbo_consumer_rt_milliseconds_p99", "The total response time spent by consumers processing 99% of requests"),
   111  	}, []float64{0.5, 0.9, 0.95, 0.99})
   112  }