-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprometheus.go
35 lines (27 loc) · 975 Bytes
/
prometheus.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
package main
import (
"context"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
var (
requestDurations = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "userli_postfix_adapter_request_duration_seconds",
Help: "Duration of requests to userli",
Buckets: prometheus.ExponentialBuckets(0.1, 1.5, 5.0),
}, []string{"handler", "status"})
)
// StartMetricsServer starts a new HTTP server for prometheus metrics.
func StartMetricsServer(ctx context.Context, listenAddr string) {
registry := prometheus.NewRegistry()
registry.MustRegister(
collectors.NewGoCollector(),
requestDurations,
)
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
log.Info("Metrics server started on ", listenAddr)
log.Fatal(http.ListenAndServe(listenAddr, nil))
}