-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetrics.go
36 lines (30 loc) · 982 Bytes
/
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
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
const namespace = "rtmp2hls"
var totalConnections = promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "connections_total",
Help: "total number of connections",
})
var currentConnections = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "connections_current",
Help: "current number of connections",
})
var totalErrors = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "total number of errors",
}, []string{"error"})
func serveMetrics() {
metricsAddr := ":2112"
http.Handle("/metrics", promhttp.Handler())
log.Infof("Metrics handler listening on %s\n", metricsAddr)
http.ListenAndServe(metricsAddr, nil)
}