ircd/monitoring.go

70 lines
2.1 KiB
Go

// vim:ts=4:sts=4:sw=4:noet:tw=72
package ircd
import (
"net/http"
"runtime"
"time"
"github.com/prometheus/client_golang/prometheus"
)
var (
gaugeGoroutinesRunning prometheus.Gauge
gaugePacketsTransferred prometheus.Gauge
gaugeConnectionsCurrent prometheus.Gauge
gaugeConnectionsCount prometheus.Gauge
gaugeLocalQueueLen prometheus.Gauge
gaugeRemoteQueueLen prometheus.Gauge
)
func monitoringRun(sv *Server) {
gaugeGoroutinesRunning = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_goroutines_running",
Help: "Goroutines runnning",
})
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",
})
gaugeLocalQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_local_queue_len",
Help: "Unhandled msgs in dispatcher local queue",
})
gaugeRemoteQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_remote_queue_len",
Help: "Unhandled msgs in dispatcher remote queue",
})
prometheus.MustRegister(gaugeGoroutinesRunning)
prometheus.MustRegister(gaugePacketsTransferred)
prometheus.MustRegister(gaugeConnectionsCurrent)
prometheus.MustRegister(gaugeConnectionsCount)
prometheus.MustRegister(gaugeLocalQueueLen)
prometheus.MustRegister(gaugeRemoteQueueLen)
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)
gaugeGoroutinesRunning.Set(float64(runtime.NumGoroutine()))
gaugePacketsTransferred.Set(sv.packetsTransferred)
gaugeConnectionsCurrent.Set(float64(len(sv.clients)))
gaugeConnectionsCount.Set(sv.connectionsCount)
gaugeLocalQueueLen.Set(float64(len(sv.localq)))
gaugeRemoteQueueLen.Set(float64(len(sv.remoteq)))
}
}