ircd/monitoring.go

48 lines
1.2 KiB
Go
Raw Normal View History

2016-07-19 16:25:39 +00:00
// 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
2016-07-20 16:17:13 +00:00
gaugeQueueLen prometheus.Gauge
2016-07-19 16:25:39 +00:00
)
2016-07-20 16:17:13 +00:00
func monitoringRun(sv *Server) {
2016-07-19 16:25:39 +00:00
gaugePacketsTransferred = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_packets_transferred",
Help: "Packets handled",
})
gaugeClientConnections = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_clients_connected",
Help: "Client connections",
})
2016-07-20 16:17:13 +00:00
gaugeQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_queue_len",
Help: "Unhandled msgs in dispatcher queue",
})
2016-07-19 16:25:39 +00:00
prometheus.MustRegister(gaugePacketsTransferred)
prometheus.MustRegister(gaugeClientConnections)
2016-07-20 16:17:13 +00:00
prometheus.MustRegister(gaugeQueueLen)
go monitoringUpdater(sv)
2016-07-19 16:25:39 +00:00
http.Handle("/metrics", prometheus.Handler())
2016-07-20 16:17:13 +00:00
laddr, _ := sv.config.GetString("net", "listen_prom")
2016-07-19 16:25:39 +00:00
http.ListenAndServe(laddr, nil)
}
2016-07-20 16:17:13 +00:00
func monitoringUpdater(sv *Server) {
2016-07-19 16:25:39 +00:00
for {
time.Sleep(5 * time.Second)
2016-07-20 16:17:13 +00:00
gaugePacketsTransferred.Set(sv.packetsTransferred)
gaugeClientConnections.Set(sv.clientConnections)
gaugeClientConnections.Set(sv.queueLen)
2016-07-19 16:25:39 +00:00
}
}