-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
54 lines (47 loc) · 1.34 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
package main
import (
"fmt"
"net/http"
"time"
log "github.com/sirupsen/logrus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/ashleyprimo/go-qr-generator/initialize"
)
var (
versionExport = promauto.NewGauge(
prometheus.GaugeOpts{
Namespace: initialize.MetricNamespace,
Name: "version",
Help: "current running version",
ConstLabels: map[string]string{
"version": initialize.Version,
},
},
)
)
func metrics() {
// Metrics Endpoint
if *initialize.EnableMetrics {
log.Debugf("Metrics Endpoint Enabled")
if *initialize.MetricServer {
log.Debugf("Metrics Server Enabled")
log.Infof("Listening for metrics requests on %s:%s", *initialize.MetricServerHost, *initialize.MetricServerPort)
go func() {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
srv := &http.Server{
Addr: fmt.Sprintf("%s:%s", *initialize.MetricServerHost, *initialize.MetricServerPort),
Handler: mux,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 3 * time.Minute,
}
log.Fatalf("Failed to start web server: %s", srv.ListenAndServe())
}()
} else {
http.Handle("/metrics", promhttp.Handler())
}
}
}