github.com/polarismesh/polaris@v1.17.8/common/metrics/discovery_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 registerDiscoveryMetrics() { 27 clientInstanceTotal = prometheus.NewGauge(prometheus.GaugeOpts{ 28 Name: "client_total", 29 Help: "polaris client instance total number", 30 ConstLabels: map[string]string{ 31 LabelServerNode: utils.LocalHost, 32 }, 33 }) 34 35 serviceCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 36 Name: "service_count", 37 Help: "service total number", 38 ConstLabels: map[string]string{ 39 LabelServerNode: utils.LocalHost, 40 }, 41 }, []string{LabelNamespace}) 42 43 serviceOnlineCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 44 Name: "service_online_count", 45 Help: "total number of service status is online", 46 ConstLabels: map[string]string{ 47 LabelServerNode: utils.LocalHost, 48 }, 49 }, []string{LabelNamespace}) 50 51 serviceAbnormalCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 52 Name: "service_abnormal_count", 53 Help: "total number of service status is abnormal", 54 ConstLabels: map[string]string{ 55 LabelServerNode: utils.LocalHost, 56 }, 57 }, []string{LabelNamespace}) 58 59 serviceOfflineCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 60 Name: "service_offline_count", 61 Help: "total number of service status is offline", 62 ConstLabels: map[string]string{ 63 LabelServerNode: utils.LocalHost, 64 }, 65 }, []string{LabelNamespace}) 66 67 instanceCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 68 Name: "instance_count", 69 Help: "instance total number", 70 ConstLabels: map[string]string{ 71 LabelServerNode: utils.LocalHost, 72 }, 73 }, []string{LabelNamespace, LabelService}) 74 75 instanceOnlineCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 76 Name: "instance_online_count", 77 Help: "total number of instance status is health", 78 ConstLabels: map[string]string{ 79 LabelServerNode: utils.LocalHost, 80 }, 81 }, []string{LabelNamespace, LabelService}) 82 83 instanceAbnormalCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 84 Name: "instance_abnormal_count", 85 Help: "total number of instance status is unhealth", 86 ConstLabels: map[string]string{ 87 LabelServerNode: utils.LocalHost, 88 }, 89 }, []string{LabelNamespace, LabelService}) 90 91 instanceIsolateCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 92 Name: "instance_isolate_count", 93 Help: "total number of instance status is isolate", 94 ConstLabels: map[string]string{ 95 LabelServerNode: utils.LocalHost, 96 }, 97 }, []string{LabelNamespace, LabelService}) 98 99 _ = GetRegistry().Register(serviceCount) 100 _ = GetRegistry().Register(serviceOnlineCount) 101 _ = GetRegistry().Register(serviceAbnormalCount) 102 _ = GetRegistry().Register(serviceOfflineCount) 103 _ = GetRegistry().Register(instanceCount) 104 _ = GetRegistry().Register(instanceOnlineCount) 105 _ = GetRegistry().Register(instanceAbnormalCount) 106 _ = GetRegistry().Register(instanceIsolateCount) 107 _ = GetRegistry().Register(clientInstanceTotal) 108 } 109 110 func GetClientInstanceTotal() prometheus.Gauge { 111 return clientInstanceTotal 112 } 113 114 func GetServiceCount() *prometheus.GaugeVec { 115 return serviceCount 116 } 117 118 func GetServiceOnlineCountl() *prometheus.GaugeVec { 119 return serviceOnlineCount 120 } 121 122 func GetServiceOfflineCountl() *prometheus.GaugeVec { 123 return serviceOfflineCount 124 } 125 126 func GetServiceAbnormalCountl() *prometheus.GaugeVec { 127 return serviceAbnormalCount 128 } 129 130 func GetInstanceCount() *prometheus.GaugeVec { 131 return instanceCount 132 } 133 134 func GetInstanceOnlineCountl() *prometheus.GaugeVec { 135 return instanceOnlineCount 136 } 137 138 func GetInstanceIsolateCountl() *prometheus.GaugeVec { 139 return instanceIsolateCount 140 } 141 142 func GetInstanceAbnormalCountl() *prometheus.GaugeVec { 143 return instanceAbnormalCount 144 }