-
Notifications
You must be signed in to change notification settings - Fork 1
/
metrics.go
49 lines (45 loc) · 1.47 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
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/siddontang/go-log/log"
)
var (
clientsConnected = promauto.NewGauge(prometheus.GaugeOpts{
Name: "proxysql_binlog_clients_connected_total",
Help: "Total number of clients connected to proxysql-binlog",
})
gtidProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "proxysql_binlog_gtid_processed_total",
Help: "Total number of GTIDs processed by proxysql-binlog",
})
clientErrors = promauto.NewCounter(prometheus.CounterOpts{
Name: "proxysql_binlog_client_erros_total",
Help: "Total number of client connection errors",
})
readerErrors = promauto.NewCounter(prometheus.CounterOpts{
Name: "proxysql_binlog_reader_erros_total",
Help: "Total number of binlog reader errors",
})
)
func NewMetricsServer() (metrics *http.Server) {
http.Handle(Config.Metrics.Endpoint, promhttp.Handler())
metrics = &http.Server{Addr: Config.Metrics.ListenAddress, Handler: nil}
go func() {
wg.Add(1)
log.Infof("Starting HTTP metrics server on %v%s", Config.Metrics.ListenAddress, Config.Metrics.Endpoint)
err := metrics.ListenAndServe()
if err != nil {
if err == http.ErrServerClosed {
log.Info("Stopping HTTP metrics server")
wg.Done()
return
}
log.Fatalf("unable to start metrics HTTP server: %v", err)
wg.Done()
}
}()
return metrics
}