github.com/m-lab/locate@v0.17.6/metrics/metrics.go (about) 1 package metrics 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 ) 7 8 var ( 9 // RequestsTotal counts the number of requests served by 10 // the Locate service. 11 // 12 // Example usage: 13 // metrics.RequestsTotal.WithLabelValues("nearest", "200").Inc() 14 RequestsTotal = promauto.NewCounterVec( 15 prometheus.CounterOpts{ 16 Name: "locate_requests_total", 17 Help: "Number of requests served by the Locate service.", 18 }, 19 []string{"type", "condition", "status"}, 20 ) 21 22 // RateLimitedTotal tracks the number of rate-limited requests by client name. 23 RateLimitedTotal = promauto.NewCounterVec( 24 prometheus.CounterOpts{ 25 Name: "locate_rate_limited_total", 26 Help: "Total number of rate-limited requests by client and limit type", 27 }, 28 []string{"clientname", "type"}, 29 ) 30 31 // AppEngineTotal counts the number of times App Engine headers are 32 // used to try to find the client location. 33 // 34 // Example usage: 35 // metrics.AppEngineTotal.WithLabelValues("US").Inc() 36 AppEngineTotal = promauto.NewCounterVec( 37 prometheus.CounterOpts{ 38 Name: "locate_app_engine_total", 39 Help: "Number of times App Engine is used to find the client location.", 40 }, 41 []string{"country"}, 42 ) 43 44 // CurrentHeartbeatConnections counts the number of currently active 45 // Heartbeat connections. 46 // 47 // Example usage: 48 // metrics.CurrentHeartbeatConnections.Inc() 49 CurrentHeartbeatConnections = promauto.NewGaugeVec( 50 prometheus.GaugeOpts{ 51 Name: "locate_current_heartbeat_connections", 52 Help: "Number of currently active Heartbeat connections.", 53 }, 54 []string{"experiment"}, 55 ) 56 57 // LocateHealthStatus exposes the health status collected by the Locate Service. 58 LocateHealthStatus = promauto.NewGaugeVec( 59 prometheus.GaugeOpts{ 60 Name: "locate_health_status", 61 Help: "Health status collected by the Locate Service.", 62 }, 63 []string{"experiment"}, 64 ) 65 66 // LocateMemorystoreRequestDuration is a histogram that tracks the latency of 67 // requests from the Locate to Memorystore. 68 LocateMemorystoreRequestDuration = promauto.NewHistogramVec( 69 prometheus.HistogramOpts{ 70 Name: "locate_memorystore_request_duration", 71 Help: "A histogram of request latency to Memorystore.", 72 Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 73 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}, 74 }, 75 []string{"type", "field", "status"}, 76 ) 77 78 // ImportMemorystoreTotal counts the number of times the Locate Service has imported 79 // the data in Memorystore. 80 ImportMemorystoreTotal = promauto.NewCounterVec( 81 prometheus.CounterOpts{ 82 Name: "locate_import_memorystore_total", 83 Help: "Number of times the Locate Service has imported the data in Memorystore.", 84 }, 85 []string{"status"}, 86 ) 87 88 // RequestHandlerDuration is a histogram that tracks the latency of each request handler. 89 RequestHandlerDuration = promauto.NewHistogramVec( 90 prometheus.HistogramOpts{ 91 Name: "locate_request_handler_duration", 92 Help: "A histogram of latencies for each request handler.", 93 }, 94 []string{"path", "code"}, 95 ) 96 97 // ServerDistanceRanking is a histogram that tracks the ranked distance of the returned servers 98 // with respect to the client. 99 // Numbering is zero-based. 100 // 101 // Example usage (the 2nd closest server to the client is returned as the 1st server in the list): 102 // metrics.ServerDistanceRanking.WithLabelValues(0).Observe(1) 103 ServerDistanceRanking = promauto.NewHistogramVec( 104 prometheus.HistogramOpts{ 105 Name: "locate_server_distance_ranking", 106 Help: "A histogram of server selection rankings with respect to distance from the client.", 107 Buckets: prometheus.LinearBuckets(0, 1, 20), 108 }, 109 []string{"index"}, 110 ) 111 112 // MetroDistanceRanking is a histogram that tracks the ranked distance of the returned metros 113 // with respect to the client. 114 // Numbering is zero-based. 115 // 116 // Example usage (the 1st server in the list is in the 2nd metro closest to the client): 117 // metrics.MetroDistanceRanking.WithLabelValues(0).Observe(1) 118 MetroDistanceRanking = promauto.NewHistogramVec( 119 prometheus.HistogramOpts{ 120 Name: "locate_metro_distance_ranking", 121 Help: "A histogram of metro selection rankings with respect to distance from the client.", 122 Buckets: prometheus.LinearBuckets(0, 1, 20), 123 }, 124 []string{"index"}, 125 ) 126 127 // ConnectionRequestsTotal counts the number of (re)connection requests the Heartbeat Service 128 // makes to the Locate Service. 129 ConnectionRequestsTotal = promauto.NewCounterVec( 130 prometheus.CounterOpts{ 131 Name: "connection_requests_total", 132 Help: "Number of connection requests from the HBS to the Locate Service.", 133 }, 134 []string{"status"}, 135 ) 136 137 // PortChecksTotal counts the number of port checks performed by the Heartbeat 138 // Service. 139 PortChecksTotal = promauto.NewCounterVec( 140 prometheus.CounterOpts{ 141 Name: "heartbeat_port_checks_total", 142 Help: "Number of port checks the HBS has done", 143 }, 144 []string{"status"}, 145 ) 146 147 // KubernetesRequestsTotal counts the number of requests from the Heartbeat 148 // Service to the Kubernetes API server. 149 KubernetesRequestsTotal = promauto.NewCounterVec( 150 prometheus.CounterOpts{ 151 Name: "heartbeat_kubernetes_requests_total", 152 Help: "Number of requests from the HBS to the Kubernetes API", 153 }, 154 []string{"type", "status"}, 155 ) 156 157 // HealthEndpointChecksTotal counts the number of local /health endpoint 158 // checks performed by the Heartbeat Service. 159 HealthEndpointChecksTotal = promauto.NewCounterVec( 160 prometheus.CounterOpts{ 161 Name: "heartbeat_health_endpoint_checks_total", 162 Help: "Number of local /health endpoint checks the HBS has done", 163 }, 164 []string{"status"}, 165 ) 166 167 // KubernetesRequestTimeHistogram tracks the request latency from the Heartbeat 168 // Service to the Kubernetes API server (in seconds). 169 KubernetesRequestTimeHistogram = promauto.NewHistogramVec( 170 prometheus.HistogramOpts{ 171 Name: "heartbeat_kubernetes_request_time_histogram", 172 Help: "Request time from the HBS to the Kubernetes API server (seconds)", 173 }, 174 []string{"healthy"}, 175 ) 176 177 // RegistrationUpdateTime tracks the time when a new registration message 178 // is retrieved from siteinfo. 179 RegistrationUpdateTime = promauto.NewGauge( 180 prometheus.GaugeOpts{ 181 Name: "heartbeat_registration_update_time", 182 Help: "Time of new registration retrieval from siteinfo.", 183 }, 184 ) 185 186 // HealthTransmissionDuration is a histogram for the latency of the heartbeat 187 // to assess local health and send it to the Locate. 188 HealthTransmissionDuration = promauto.NewHistogramVec( 189 prometheus.HistogramOpts{ 190 Name: "heartbeat_health_transmission_duration", 191 Help: "Latency for the heartbeat to assess local health and send it.", 192 Buckets: prometheus.LinearBuckets(0, 2, 16), 193 }, 194 []string{"score"}, 195 ) 196 )