1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 10:22:19 +00:00

Do not read prometheus metrics

This commit is contained in:
Alexandre Iooss 2020-09-29 18:17:55 +02:00
parent 2005f3ece1
commit 078a74add1
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
4 changed files with 8 additions and 15 deletions

2
go.mod
View File

@ -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
)

View File

@ -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()

View File

@ -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 {

View File

@ -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()})
}