forked from tleyden/open-ocr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprometheus_metrics.go
59 lines (52 loc) · 1.89 KB
/
prometheus_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
package ocrworker
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
inFlightGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ocr_in_flight_requests",
Help: "Number of currently pending and processed requests.",
})
counter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "ocr_api_requests_total",
Help: "A counter for http requests.",
},
[]string{"code", "method"},
)
// duration is partitioned by the HTTP method and handler. It uses custom
// buckets based on the expected request duration.
duration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "ocr_request_duration_seconds",
Help: "A histogram of latencies for requests.",
Buckets: []float64{.01, .05, .1, .25, .5, 1, 2.5, 5, 10},
},
[]string{"handler", "method"},
)
// requestSize has no labels, making it a zero-dimensional ObserverVec.
requestSize = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "ocr_request_size_bytes",
Help: "A histogram of response sizes for requests.",
Buckets: []float64{100, 1500, 5000000, 10000000, 25000000, 50000000},
},
[]string{},
)
)
// InstrumentHttpStatusHandler wraps httpHandler to provide prometheus metrics
func InstrumentHttpStatusHandler(ocrHttpHandler *OcrHTTPStatusHandler) http.Handler {
// Register all the metrics in the standard registry.
prometheus.MustRegister(inFlightGauge, counter, duration, requestSize)
ocrChain := promhttp.InstrumentHandlerInFlight(inFlightGauge,
promhttp.InstrumentHandlerDuration(duration.MustCurryWith(prometheus.Labels{"handler": "ocr"}),
promhttp.InstrumentHandlerCounter(counter,
// promhttp.InstrumentHandlerRequestSize(requestSize, ocrworker.NewOcrHttpHandler(rabbitConfig)),
promhttp.InstrumentHandlerRequestSize(requestSize, ocrHttpHandler),
),
),
)
return ocrChain
}