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
|
2016-07-20 22:03:37 +00:00
|
|
|
gaugeConnectionsCurrent prometheus.Gauge
|
|
|
|
gaugeConnectionsCount 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",
|
|
|
|
})
|
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-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)
|
2016-07-20 22:03:37 +00:00
|
|
|
prometheus.MustRegister(gaugeConnectionsCurrent)
|
|
|
|
prometheus.MustRegister(gaugeConnectionsCount)
|
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)
|
2016-07-20 22:03:37 +00:00
|
|
|
gaugeConnectionsCurrent.Set(sv.connectionsCurrent)
|
|
|
|
gaugeConnectionsCount.Set(sv.connectionsCount)
|
|
|
|
gaugeQueueLen.Set(sv.queueLen)
|
2016-07-19 16:25:39 +00:00
|
|
|
}
|
|
|
|
}
|