ircd/monitoring.go

70 lines
2.1 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"
2016-08-12 21:18:39 +00:00
"runtime"
2016-07-19 16:25:39 +00:00
"time"
"github.com/prometheus/client_golang/prometheus"
)
var (
2016-08-12 21:18:39 +00:00
gaugeGoroutinesRunning prometheus.Gauge
2016-07-19 16:25:39 +00:00
gaugePacketsTransferred prometheus.Gauge
2016-07-20 22:03:37 +00:00
gaugeConnectionsCurrent prometheus.Gauge
gaugeConnectionsCount prometheus.Gauge
2016-08-12 21:18:39 +00:00
gaugeLocalQueueLen prometheus.Gauge
gaugeRemoteQueueLen prometheus.Gauge
2016-07-19 16:25:39 +00:00
)
2016-07-20 16:17:13 +00:00
func monitoringRun(sv *Server) {
2016-08-12 21:18:39 +00:00
gaugeGoroutinesRunning = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_goroutines_running",
Help: "Goroutines runnning",
})
2016-07-19 16:25:39 +00:00
gaugePacketsTransferred = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_packets_transferred",
Help: "Packets handled",
})
2016-07-20 22:03:37 +00:00
gaugeConnectionsCurrent = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_connections_current",
Help: "Client connections",
})
gaugeConnectionsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_connections_count",
2016-07-19 16:25:39 +00:00
Help: "Client connections",
})
2016-08-12 21:18:39 +00:00
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",
2016-07-20 16:17:13 +00:00
})
2016-08-12 21:18:39 +00:00
prometheus.MustRegister(gaugeGoroutinesRunning)
2016-07-19 16:25:39 +00:00
prometheus.MustRegister(gaugePacketsTransferred)
2016-07-20 22:03:37 +00:00
prometheus.MustRegister(gaugeConnectionsCurrent)
prometheus.MustRegister(gaugeConnectionsCount)
2016-08-12 21:18:39 +00:00
prometheus.MustRegister(gaugeLocalQueueLen)
prometheus.MustRegister(gaugeRemoteQueueLen)
2016-07-20 16:17:13 +00:00
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-08-12 21:18:39 +00:00
gaugeGoroutinesRunning.Set(float64(runtime.NumGoroutine()))
2016-07-20 16:17:13 +00:00
gaugePacketsTransferred.Set(sv.packetsTransferred)
2016-08-12 21:18:39 +00:00
gaugeConnectionsCurrent.Set(float64(len(sv.clients)))
2016-07-20 22:03:37 +00:00
gaugeConnectionsCount.Set(sv.connectionsCount)
2016-08-12 21:18:39 +00:00
gaugeLocalQueueLen.Set(float64(len(sv.localq)))
gaugeRemoteQueueLen.Set(float64(len(sv.remoteq)))
2016-07-19 16:25:39 +00:00
}
}