-
Notifications
You must be signed in to change notification settings - Fork 55
/
metrics.go
114 lines (100 loc) · 3.31 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package bramble
import (
"net/http"
"net/http/pprof"
"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",
})
promServiceUpdateErrorCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "service_update_error_total",
Help: "A counter indicating how many times services have failed to update",
},
[]string{
"service",
},
)
promServiceTimeoutErrorCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "service_timeout_error_total",
Help: "A counter indicating how many times services have timed out",
},
[]string{
"service",
},
)
promServiceUpdateErrorGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "service_update_error",
Help: "A gauge indicating what services are failing 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(promServiceTimeoutErrorCounter)
prometheus.MustRegister(promServiceUpdateErrorCounter)
prometheus.MustRegister(promServiceUpdateErrorGauge)
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())
mux.HandleFunc("/debug/pprof/", pprof.Index)
return mux
}