forked from movio/bramble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
90 lines (78 loc) · 2.66 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package bramble
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
// promInvalidSchema is a gauge representing the current status of remote services schemas
promInvalidSchema = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "invalid_schema",
Help: "A gauge representing the current status of remote services schemas",
})
promServiceUpdateError = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "service_update_error",
Help: "A counter indicating what services have failed to update",
},
[]string{
"service",
},
)
// promHTTPInFlightGauge is a gauge of requests currently being served by the wrapped handler
promHTTPInFlightGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "http_in_flight_requests",
Help: "A gauge of requests currently being served",
})
// promHTTPRequestCounter is a counter for requests to the wrapped handler
promHTTPRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "http_api_requests_total",
Help: "A counter for served requests",
},
[]string{"code"},
)
// promHTTPResponseDurations is a histogram of request latencies
promHTTPResponseDurations = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_response_duration_seconds",
Help: "A histogram of request latencies",
Buckets: prometheus.DefBuckets,
},
[]string{},
)
// promHTTPRequestSizes is a histogram of request sizes for requests
promHTTPRequestSizes = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_size_bytes",
Help: "A histogram of request sizes for requests",
Buckets: prometheus.ExponentialBuckets(128, 2, 10),
},
[]string{},
)
// promHTTPResponseSizes is a histogram of response sizes for responses.
promHTTPResponseSizes = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_response_size_bytes",
Help: "A histogram of response sizes for responses",
Buckets: prometheus.ExponentialBuckets(1024, 2, 10),
},
[]string{},
)
)
// RegisterMetrics register the prometheus metrics.
func RegisterMetrics() {
prometheus.MustRegister(promInvalidSchema)
prometheus.MustRegister(promServiceUpdateError)
prometheus.MustRegister(promHTTPInFlightGauge)
prometheus.MustRegister(promHTTPRequestCounter)
prometheus.MustRegister(promHTTPResponseDurations)
prometheus.MustRegister(promHTTPRequestSizes)
prometheus.MustRegister(promHTTPResponseSizes)
}
// NewMetricsHandler returns a new Prometheus metrics handler.
func NewMetricsHandler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
return mux
}