github.com/thanos-io/thanos@v0.32.5/pkg/extprom/http/metrics.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package http 5 6 import ( 7 "github.com/prometheus/client_golang/prometheus" 8 "github.com/prometheus/client_golang/prometheus/promauto" 9 ) 10 11 type defaultMetrics struct { 12 requestDuration *prometheus.HistogramVec 13 requestSize *prometheus.HistogramVec 14 requestsTotal *prometheus.CounterVec 15 responseSize *prometheus.HistogramVec 16 inflightHTTPRequests *prometheus.GaugeVec 17 } 18 19 func newDefaultMetrics(reg prometheus.Registerer, durationBuckets []float64, extraLabels []string) *defaultMetrics { 20 if durationBuckets == nil { 21 durationBuckets = []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720} 22 } 23 24 bytesBuckets := prometheus.ExponentialBuckets(64, 2, 10) 25 bucketFactor := 1.1 26 maxBuckets := uint32(100) 27 28 return &defaultMetrics{ 29 requestDuration: promauto.With(reg).NewHistogramVec( 30 prometheus.HistogramOpts{ 31 Name: "http_request_duration_seconds", 32 Help: "Tracks the latencies for HTTP requests.", 33 Buckets: durationBuckets, 34 NativeHistogramBucketFactor: bucketFactor, 35 NativeHistogramMaxBucketNumber: maxBuckets, 36 }, 37 append([]string{"code", "handler", "method"}, extraLabels...), 38 ), 39 40 requestSize: promauto.With(reg).NewHistogramVec( 41 prometheus.HistogramOpts{ 42 Name: "http_request_size_bytes", 43 Help: "Tracks the size of HTTP requests.", 44 Buckets: bytesBuckets, 45 NativeHistogramBucketFactor: bucketFactor, 46 NativeHistogramMaxBucketNumber: maxBuckets, 47 }, 48 append([]string{"code", "handler", "method"}, extraLabels...), 49 ), 50 51 requestsTotal: promauto.With(reg).NewCounterVec( 52 prometheus.CounterOpts{ 53 Name: "http_requests_total", 54 Help: "Tracks the number of HTTP requests.", 55 }, 56 append([]string{"code", "handler", "method"}, extraLabels...), 57 ), 58 59 responseSize: promauto.With(reg).NewHistogramVec( 60 prometheus.HistogramOpts{ 61 Name: "http_response_size_bytes", 62 Help: "Tracks the size of HTTP responses.", 63 Buckets: bytesBuckets, 64 NativeHistogramBucketFactor: bucketFactor, 65 NativeHistogramMaxBucketNumber: maxBuckets, 66 }, 67 append([]string{"code", "handler", "method"}, extraLabels...), 68 ), 69 70 inflightHTTPRequests: promauto.With(reg).NewGaugeVec( 71 prometheus.GaugeOpts{ 72 Name: "http_inflight_requests", 73 Help: "Current number of HTTP requests the handler is responding to.", 74 }, 75 append([]string{"handler", "method"}, extraLabels...), 76 ), 77 } 78 }