(ctx caddy.Context, metrics *Metrics)
| 100 | } |
| 101 | |
| 102 | func initHTTPMetrics(ctx caddy.Context, metrics *Metrics) { |
| 103 | const ns, sub = "caddy", "http" |
| 104 | registry := ctx.GetMetricsRegistry() |
| 105 | basicLabels := []string{"server", "handler"} |
| 106 | if metrics.PerHost { |
| 107 | basicLabels = append(basicLabels, "host") |
| 108 | } |
| 109 | metrics.httpMetrics.requestInFlight = promauto.With(registry).NewGaugeVec(prometheus.GaugeOpts{ |
| 110 | Namespace: ns, |
| 111 | Subsystem: sub, |
| 112 | Name: "requests_in_flight", |
| 113 | Help: "Number of requests currently handled by this server.", |
| 114 | }, basicLabels) |
| 115 | metrics.httpMetrics.requestErrors = promauto.With(registry).NewCounterVec(prometheus.CounterOpts{ |
| 116 | Namespace: ns, |
| 117 | Subsystem: sub, |
| 118 | Name: "request_errors_total", |
| 119 | Help: "Number of requests resulting in middleware errors.", |
| 120 | }, basicLabels) |
| 121 | metrics.httpMetrics.requestCount = promauto.With(registry).NewCounterVec(prometheus.CounterOpts{ |
| 122 | Namespace: ns, |
| 123 | Subsystem: sub, |
| 124 | Name: "requests_total", |
| 125 | Help: "Counter of HTTP(S) requests made.", |
| 126 | }, basicLabels) |
| 127 | |
| 128 | // TODO: allow these to be customized in the config |
| 129 | durationBuckets := prometheus.DefBuckets |
| 130 | sizeBuckets := prometheus.ExponentialBuckets(256, 4, 8) |
| 131 | |
| 132 | httpLabels := []string{"server", "handler", "code", "method"} |
| 133 | if metrics.PerHost { |
| 134 | httpLabels = append(httpLabels, "host") |
| 135 | } |
| 136 | metrics.httpMetrics.requestDuration = promauto.With(registry).NewHistogramVec(prometheus.HistogramOpts{ |
| 137 | Namespace: ns, |
| 138 | Subsystem: sub, |
| 139 | Name: "request_duration_seconds", |
| 140 | Help: "Histogram of round-trip request durations.", |
| 141 | Buckets: durationBuckets, |
| 142 | }, httpLabels) |
| 143 | metrics.httpMetrics.requestSize = promauto.With(registry).NewHistogramVec(prometheus.HistogramOpts{ |
| 144 | Namespace: ns, |
| 145 | Subsystem: sub, |
| 146 | Name: "request_size_bytes", |
| 147 | Help: "Total size of the request. Includes body", |
| 148 | Buckets: sizeBuckets, |
| 149 | }, httpLabels) |
| 150 | metrics.httpMetrics.responseSize = promauto.With(registry).NewHistogramVec(prometheus.HistogramOpts{ |
| 151 | Namespace: ns, |
| 152 | Subsystem: sub, |
| 153 | Name: "response_size_bytes", |
| 154 | Help: "Size of the returned response.", |
| 155 | Buckets: sizeBuckets, |
| 156 | }, httpLabels) |
| 157 | metrics.httpMetrics.responseDuration = promauto.With(registry).NewHistogramVec(prometheus.HistogramOpts{ |
| 158 | Namespace: ns, |
| 159 | Subsystem: sub, |
no test coverage detected