github.com/polarismesh/polaris@v1.17.8/common/metrics/types.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 "strconv" 22 "time" 23 24 "github.com/prometheus/client_golang/prometheus" 25 ) 26 27 const ( 28 LabelServerNode = "polaris_server_instance" 29 LabelNamespace = "namespace" 30 LabelService = "service" 31 LabelGroup = "group" 32 LabelVersion = "version" 33 LabelApi = "api" 34 LabelApiType = "api_type" 35 LabelProtocol = "protocol" 36 LabelErrCode = "err_code" 37 labelCacheType = "cache_type" 38 labelCacheUpdateCount = "cache_update_count" 39 labelBatchJobLabel = "batch_label" 40 ) 41 42 // CallMetricType . 43 type CallMetricType string 44 45 const ( 46 // SystemCallMetric Time consuming statistics of some asynchronous tasks inside 47 SystemCallMetric CallMetricType = "innerCall" 48 // ServerCallMetric Apiserver-layer interface call consumption statistics 49 ServerCallMetric CallMetricType = "serverCall" 50 // RedisCallMetric Redis call time consumption statistics 51 RedisCallMetric CallMetricType = "redisCall" 52 // StoreCallMetric Store call time consumption statistics 53 StoreCallMetric CallMetricType = "storeCall" 54 // ProtobufCacheCallMetric PB encode cache call/hit statistics 55 ProtobufCacheCallMetric CallMetricType = "pbCacheCall" 56 ) 57 58 type CallMetric struct { 59 Type CallMetricType 60 API string 61 Protocol string 62 Code int 63 Times int 64 Success bool 65 Duration time.Duration 66 Labels map[string]string 67 } 68 69 func (m CallMetric) GetLabels() map[string]string { 70 if len(m.Labels) == 0 { 71 m.Labels = map[string]string{} 72 } 73 m.Labels[LabelApi] = m.API 74 m.Labels[LabelProtocol] = m.Protocol 75 m.Labels[LabelErrCode] = strconv.FormatInt(int64(m.Code), 10) 76 return m.Labels 77 } 78 79 type DiscoveryMetricType string 80 81 const ( 82 ClientMetrics DiscoveryMetricType = "client" 83 ServiceMetrics DiscoveryMetricType = "service" 84 InstanceMetrics DiscoveryMetricType = "instance" 85 ) 86 87 type DiscoveryMetric struct { 88 Type DiscoveryMetricType 89 Total int64 90 Abnormal int64 91 Offline int64 92 Online int64 93 Isolate int64 94 Labels map[string]string 95 } 96 97 type ConfigMetricType string 98 99 const ( 100 ConfigGroupMetric ConfigMetricType = "config_group" 101 FileMetric ConfigMetricType = "file" 102 ReleaseFileMetric ConfigMetricType = "release_file" 103 ) 104 105 type ConfigMetrics struct { 106 Type ConfigMetricType 107 Total int64 108 Release int64 109 Labels map[string]string 110 } 111 112 var ( 113 clientInstanceTotal prometheus.Gauge 114 serviceCount *prometheus.GaugeVec 115 serviceOnlineCount *prometheus.GaugeVec 116 serviceAbnormalCount *prometheus.GaugeVec 117 serviceOfflineCount *prometheus.GaugeVec 118 instanceCount *prometheus.GaugeVec 119 instanceOnlineCount *prometheus.GaugeVec 120 instanceAbnormalCount *prometheus.GaugeVec 121 instanceIsolateCount *prometheus.GaugeVec 122 ) 123 124 var ( 125 configGroupTotal *prometheus.GaugeVec 126 configFileTotal *prometheus.GaugeVec 127 releaseConfigFileTotal *prometheus.GaugeVec 128 ) 129 130 // instance astbc registry metrics 131 var ( 132 // instanceAsyncRegisCost 实例异步注册任务耗费时间 133 instanceAsyncRegisCost prometheus.Histogram 134 // instanceRegisTaskExpire 实例异步注册任务超时无效事件 135 instanceRegisTaskExpire prometheus.Counter 136 redisReadFailure prometheus.Gauge 137 redisWriteFailure prometheus.Gauge 138 redisAliveStatus prometheus.Gauge 139 // discoveryConnTotal 服务发现客户端链接数量 140 discoveryConnTotal prometheus.Gauge 141 // configurationConnTotal 配置中心客户端链接数量 142 configurationConnTotal prometheus.Gauge 143 // sdkClientTotal 客户端链接数量 144 sdkClientTotal prometheus.Gauge 145 cacheUpdateCost *prometheus.HistogramVec 146 // batchJobUnFinishJobs . 147 batchJobUnFinishJobs *prometheus.GaugeVec 148 )