-
Notifications
You must be signed in to change notification settings - Fork 21
/
metrics.go
64 lines (59 loc) · 2.13 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func wrapPrometheusMetrics(handler http.Handler) http.Handler {
counter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "s3proxy_api_requests_total",
Help: "A counter for requests to the wrapped handler.",
},
[]string{"code", "method"},
)
duration := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "s3proxy_request_duration_seconds",
Help: "A histogram of latencies for requests.",
Buckets: []float64{.25, .5, 0.75, 1, 2.5, 5, 10},
},
[]string{"handler", "method"},
)
inFlight := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "s3proxy_in_flight_requests",
Help: "A gauge of requests currently being served by the wrapped handler.",
})
requestSize := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "s3proxy_request_size_bytes",
Help: "A histogram of request sizes.",
Buckets: []float64{200, 500, 900, 1500, 4100, 8200, 16400, 32800},
},
[]string{},
)
responseSize := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "s3proxy_response_size_bytes",
Help: "A histogram of response sizes for requests.",
Buckets: []float64{200, 500, 900, 1500, 4100, 8200, 16400, 32800},
},
[]string{},
)
timeToWriteHeader := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "s3proxy_time_to_write_header",
Help: "A histogram of time to write heaer.",
Buckets: []float64{0.25, 0.5, 0.75, 1, 2.5, 5, 10},
},
[]string{},
)
// Register all of the metrics in the standard registry.
prometheus.MustRegister(counter, duration, inFlight, requestSize, responseSize, timeToWriteHeader)
return promhttp.InstrumentHandlerCounter(counter,
promhttp.InstrumentHandlerDuration(duration.MustCurryWith(prometheus.Labels{"handler": "pull"}),
promhttp.InstrumentHandlerInFlight(inFlight,
promhttp.InstrumentHandlerRequestSize(requestSize,
promhttp.InstrumentHandlerResponseSize(responseSize,
promhttp.InstrumentHandlerTimeToWriteHeader(timeToWriteHeader, handler))))))
}