-
Notifications
You must be signed in to change notification settings - Fork 11
/
metrics.go
34 lines (30 loc) · 892 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
package main
import (
"fmt"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
activeSessions = promauto.NewGauge(prometheus.GaugeOpts{
Name: "active_sessions",
Help: "The current number of active sessions",
})
totalConnections = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "connections_total",
Help: "The total number of connection attempts",
}, []string{"ip"})
totalSessions = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "sessions_total",
Help: "The total number of established sessions",
}, []string{"user", "ip"})
)
func serveMetrics(bind string) {
http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(bind, nil); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
}
}