// 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 ) func monitoringRun(srv *Server) { gaugePacketsTransferred = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "ircd_packets_transferred", Help: "Packets handled", }) gaugeClientConnections = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "ircd_clients_connected", Help: "Client connections", }) prometheus.MustRegister(gaugePacketsTransferred) prometheus.MustRegister(gaugeClientConnections) go monitoringUpdater(srv) http.Handle("/metrics", prometheus.Handler()) laddr, _ := srv.config.GetString("net", "listen_prom") http.ListenAndServe(laddr, nil) } func monitoringUpdater(srv *Server) { for { time.Sleep(5 * time.Second) gaugePacketsTransferred.Set(srv.packetsTransferred) gaugeClientConnections.Set(srv.clientConnections) } }