github.com/polarismesh/polaris@v1.17.8/common/metrics/client_metrics.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package metrics 19 20 import ( 21 "github.com/prometheus/client_golang/prometheus" 22 23 "github.com/polarismesh/polaris/common/utils" 24 ) 25 26 func registerClientMetrics() { 27 // discoveryConnTotal 服务发现客户端链接数量 28 discoveryConnTotal = prometheus.NewGauge(prometheus.GaugeOpts{ 29 Name: "discovery_conn_total", 30 Help: "polaris discovery client connection total", 31 ConstLabels: map[string]string{ 32 LabelServerNode: utils.LocalHost, 33 }, 34 }) 35 36 // configurationConnTotal 配置中心客户端链接数量 37 configurationConnTotal = prometheus.NewGauge(prometheus.GaugeOpts{ 38 Name: "config_conn_total", 39 Help: "polaris configuration client connection total", 40 ConstLabels: map[string]string{ 41 LabelServerNode: utils.LocalHost, 42 }, 43 }) 44 45 // sdkClientTotal 客户端链接数量 46 sdkClientTotal = prometheus.NewGauge(prometheus.GaugeOpts{ 47 Name: "sdk_client_total", 48 Help: "polaris client connection total", 49 ConstLabels: map[string]string{ 50 LabelServerNode: utils.LocalHost, 51 }, 52 }) 53 54 _ = GetRegistry().Register(discoveryConnTotal) 55 _ = GetRegistry().Register(configurationConnTotal) 56 _ = GetRegistry().Register(sdkClientTotal) 57 } 58 59 // AddDiscoveryClientConn add discovery client connection number 60 func AddDiscoveryClientConn() { 61 discoveryConnTotal.Inc() 62 } 63 64 // RemoveDiscoveryClientConn remove discovery client connection number 65 func RemoveDiscoveryClientConn() { 66 discoveryConnTotal.Dec() 67 } 68 69 // ResetDiscoveryClientConn reset discovery client connection number 70 func ResetDiscoveryClientConn() { 71 discoveryConnTotal.Set(0) 72 } 73 74 // AddConfigurationClientConn add configuration client connection number 75 func AddConfigurationClientConn() { 76 configurationConnTotal.Inc() 77 } 78 79 // RemoveConfigurationClientConn remove configuration client connection number 80 func RemoveConfigurationClientConn() { 81 configurationConnTotal.Dec() 82 } 83 84 // ResetConfigurationClientConn reset configuration client connection number 85 func ResetConfigurationClientConn() { 86 configurationConnTotal.Set(0) 87 } 88 89 // AddSDKClientConn add client connection number 90 func AddSDKClientConn() { 91 sdkClientTotal.Inc() 92 } 93 94 // RemoveSDKClientConn remove client connection number 95 func RemoveSDKClientConn() { 96 sdkClientTotal.Dec() 97 } 98 99 // Conn reset client connection number 100 func ResetSDKClientConn() { 101 sdkClientTotal.Set(0) 102 }