From 078a74add11cd882d345ebe56869b677f9447903 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Tue, 29 Sep 2020 18:17:55 +0200 Subject: [PATCH] Do not read prometheus metrics --- go.mod | 2 -- internal/monitoring/monitoring.go | 10 ---------- stream/webrtc/webrtc.go | 7 ++++++- web/handler.go | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 95daab6..4fa3bbb 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,10 @@ go 1.13 require ( github.com/go-ldap/ldap/v3 v3.2.3 github.com/haivision/srtgo v0.0.0-20200731151239-e00427ae473a - github.com/hashicorp/go.net v0.0.1 github.com/markbates/pkger v0.17.1 github.com/pion/rtp v1.6.0 github.com/pion/webrtc/v3 v3.0.0-beta.5 github.com/prometheus/client_golang v1.7.1 - github.com/prometheus/client_model v0.2.0 github.com/spf13/viper v1.7.1 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 ) diff --git a/internal/monitoring/monitoring.go b/internal/monitoring/monitoring.go index 8445f2d..e3f2d0c 100644 --- a/internal/monitoring/monitoring.go +++ b/internal/monitoring/monitoring.go @@ -7,7 +7,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" - dto "github.com/prometheus/client_model/go" ) // Options holds web package configuration @@ -35,15 +34,6 @@ var ( }) ) -func GetGaugeValue(metric prometheus.Gauge) float64 { - var m = &dto.Metric{} - if err := metric.Write(m); err != nil { - log.Fatal(err) - return 0 - } - return m.Gauge.GetValue() -} - // Serve monitoring server that expose prometheus metrics func Serve(cfg *Options) { mux := http.NewServeMux() diff --git a/stream/webrtc/webrtc.go b/stream/webrtc/webrtc.go index ed23876..08a9e88 100644 --- a/stream/webrtc/webrtc.go +++ b/stream/webrtc/webrtc.go @@ -2,7 +2,6 @@ package webrtc import ( "fmt" - "gitlab.crans.org/nounous/ghostream/internal/monitoring" "io" "log" "math/rand" @@ -13,6 +12,7 @@ import ( "github.com/pion/webrtc/v3/pkg/media" "github.com/pion/webrtc/v3/pkg/media/ivfreader" "github.com/pion/webrtc/v3/pkg/media/oggreader" + "gitlab.crans.org/nounous/ghostream/internal/monitoring" ) // Options holds web package configuration @@ -47,6 +47,11 @@ func removeTrack(tracks []*webrtc.Track, track *webrtc.Track) []*webrtc.Track { return nil } +// GetNumberConnectedSessions get the number of currently connected clients +func GetNumberConnectedSessions() int { + return len(videoTracks) +} + // newPeerHandler is called when server receive a new session description // this initiates a WebRTC connection and return server description func newPeerHandler(remoteSdp webrtc.SessionDescription, cfg *Options) webrtc.SessionDescription { diff --git a/web/handler.go b/web/handler.go index fef5ffc..e82f977 100644 --- a/web/handler.go +++ b/web/handler.go @@ -6,8 +6,8 @@ import ( "net/http" "github.com/markbates/pkger" - "github.com/pion/webrtc/v3" "gitlab.crans.org/nounous/ghostream/internal/monitoring" + "gitlab.crans.org/nounous/ghostream/stream/webrtc" ) // Handle WebRTC session description exchange via POST @@ -90,5 +90,5 @@ func statisticsHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) enc.Encode(struct { ConnectedViewers int - }{int(monitoring.GetGaugeValue(monitoring.WebRTCConnectedSessions))}) + }{webrtc.GetNumberConnectedSessions()}) }