48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// vim:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
package ircd
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var (
|
|
gaugePacketsTransferred prometheus.Gauge
|
|
gaugeClientConnections prometheus.Gauge
|
|
gaugeQueueLen prometheus.Gauge
|
|
)
|
|
|
|
func monitoringRun(sv *Server) {
|
|
gaugePacketsTransferred = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
Name: "ircd_packets_transferred",
|
|
Help: "Packets handled",
|
|
})
|
|
gaugeClientConnections = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
Name: "ircd_clients_connected",
|
|
Help: "Client connections",
|
|
})
|
|
gaugeQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
Name: "ircd_queue_len",
|
|
Help: "Unhandled msgs in dispatcher queue",
|
|
})
|
|
prometheus.MustRegister(gaugePacketsTransferred)
|
|
prometheus.MustRegister(gaugeClientConnections)
|
|
prometheus.MustRegister(gaugeQueueLen)
|
|
go monitoringUpdater(sv)
|
|
http.Handle("/metrics", prometheus.Handler())
|
|
laddr, _ := sv.config.GetString("net", "listen_prom")
|
|
http.ListenAndServe(laddr, nil)
|
|
}
|
|
|
|
func monitoringUpdater(sv *Server) {
|
|
for {
|
|
time.Sleep(5 * time.Second)
|
|
gaugePacketsTransferred.Set(sv.packetsTransferred)
|
|
gaugeClientConnections.Set(sv.clientConnections)
|
|
gaugeClientConnections.Set(sv.queueLen)
|
|
}
|
|
}
|