ircd/monitoring.go

55 lines
1.5 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
gaugeConnectionsCurrent prometheus.Gauge
gaugeConnectionsCount prometheus.Gauge
gaugeQueueLen prometheus.Gauge
)
func monitoringRun(sv *Server) {
gaugePacketsTransferred = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_packets_transferred",
Help: "Packets handled",
})
gaugeConnectionsCurrent = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_connections_current",
Help: "Client connections",
})
gaugeConnectionsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_connections_count",
Help: "Client connections",
})
gaugeQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_queue_len",
Help: "Unhandled msgs in dispatcher queue",
})
prometheus.MustRegister(gaugePacketsTransferred)
prometheus.MustRegister(gaugeConnectionsCurrent)
prometheus.MustRegister(gaugeConnectionsCount)
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)
gaugeConnectionsCurrent.Set(sv.connectionsCurrent)
gaugeConnectionsCount.Set(sv.connectionsCount)
gaugeQueueLen.Set(sv.queueLen)
}
}