1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 11:28:51 +02:00

Store connected viewers in Prometheus and serve this amount

This commit is contained in:
Yohann D'ANELLO
2020-09-29 18:03:28 +02:00
parent c49b5eeb2b
commit 2005f3ece1
6 changed files with 31 additions and 0 deletions

View File

@ -84,3 +84,11 @@ func staticHandler() http.Handler {
staticFs := http.FileServer(pkger.Dir("/web/static"))
return http.StripPrefix("/static/", staticFs)
}
func statisticsHandler(w http.ResponseWriter, r *http.Request) {
// Display connected users stats
enc := json.NewEncoder(w)
enc.Encode(struct {
ConnectedViewers int
}{int(monitoring.GetGaugeValue(monitoring.WebRTCConnectedSessions))})
}

View File

@ -84,6 +84,7 @@ func Serve(rSdpChan chan webrtc.SessionDescription, lSdpChan chan webrtc.Session
mux := http.NewServeMux()
mux.HandleFunc("/", viewerHandler)
mux.Handle("/static/", staticHandler())
mux.HandleFunc("/_stats/", statisticsHandler)
log.Printf("HTTP server listening on %s", cfg.ListenAddress)
log.Fatal(http.ListenAndServe(cfg.ListenAddress, mux))
}