-
Notifications
You must be signed in to change notification settings - Fork 18
/
metrics.go
37 lines (32 loc) · 1.04 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
package lib
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)
var (
ErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "nirn_proxy_error",
Help: "The total number of errors when processing requests",
})
RequestHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "nirn_proxy_requests",
Help: "Request histogram",
Buckets: []float64{.1, .25, 1, 2.5, 5, 20},
}, []string{"method", "status", "route", "clientId"})
ConnectionsOpen = promauto.NewGauge(prometheus.GaugeOpts{
Name: "nirn_proxy_open_connections",
Help: "Gauge for client connections currently open with the proxy",
})
)
func StartMetrics(addr string) {
prometheus.MustRegister(RequestHistogram)
http.Handle("/metrics", promhttp.Handler())
logger.Info("Starting metrics server on " + addr)
err := http.ListenAndServe(addr, nil)
if err != nil {
logger.Error(err)
return
}
}