From 4d260412c4162881974f59c79199c162b015f4da Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 8 May 2021 22:52:10 +0200 Subject: [PATCH] remove number of clients from logs --- README.md | 6 ++---- go.mod | 2 +- go.sum | 4 ++-- internal/clientrtmp/client.go | 3 --- internal/clientrtsp/client.go | 3 --- internal/converterhls/converter.go | 1 - internal/metrics/metrics.go | 6 +++--- internal/sessionrtsp/session.go | 4 ++-- internal/stats/stats.go | 2 -- main.go | 3 +-- 10 files changed, 11 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1c611cff..2a3ac8de 100644 --- a/README.md +++ b/README.md @@ -475,10 +475,10 @@ There are multiple ways to monitor the server usage over time: * The current number of clients, publishers and readers is printed in each log line; for instance, the line: ``` - 2020/01/01 00:00:00 [2/1/1] [client 127.0.0.1:44428] OPTION + 2020/01/01 00:00:00 [3/2] [client 127.0.0.1:44428] OPTION ``` - means that there are 2 clients, 1 publisher and 1 reader. + means that there are 3 publishers and 2 readers. * A metrics exporter, compatible with Prometheus, can be enabled with the parameter `metrics: yes`; then the server can be queried for metrics with Prometheus or with a simple HTTP request: @@ -489,7 +489,6 @@ There are multiple ways to monitor the server usage over time: Obtaining: ``` - rtsp_clients{state="idle"} 2 1596122687740 rtsp_clients{state="publishing"} 15 1596122687740 rtsp_clients{state="reading"} 8 1596122687740 rtsp_sources{type="rtsp",state="idle"} 3 1596122687740 @@ -500,7 +499,6 @@ There are multiple ways to monitor the server usage over time: where: - * `rtsp_clients{state="idle"}` is the count of clients that are neither publishing nor reading * `rtsp_clients{state="publishing"}` is the count of clients that are publishing * `rtsp_clients{state="reading"}` is the count of clients that are reading * `rtsp_sources{type="rtsp",state="idle"}` is the count of rtsp sources that are not running diff --git a/go.mod b/go.mod index e704c232..c6402db2 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/aler9/gortsplib v0.0.0-20210508202705-7469a3362a7d + github.com/aler9/gortsplib v0.0.0-20210508203529-1b9b19dd8493 github.com/asticode/go-astits v0.0.0-00010101000000-000000000000 github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.4.9 diff --git a/go.sum b/go.sum index 0a425c5f..547d8a48 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04 h1:CXgQLsU4uxWAmsXNOjGLbj0A+0IlRcpZpMgI13fmVwo= github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ= -github.com/aler9/gortsplib v0.0.0-20210508202705-7469a3362a7d h1:c9eARLYpLvZM6WX7TLIgp1z7NvpYxK4ceFdx62te6YU= -github.com/aler9/gortsplib v0.0.0-20210508202705-7469a3362a7d/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY= +github.com/aler9/gortsplib v0.0.0-20210508203529-1b9b19dd8493 h1:fyc2te2rF8JIRuft//GORUYH6UYfQCKuiaoEmM0JCEc= +github.com/aler9/gortsplib v0.0.0-20210508203529-1b9b19dd8493/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc= github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8= diff --git a/internal/clientrtmp/client.go b/internal/clientrtmp/client.go index 4c731e04..ef914393 100644 --- a/internal/clientrtmp/client.go +++ b/internal/clientrtmp/client.go @@ -7,7 +7,6 @@ import ( "net/url" "strings" "sync" - "sync/atomic" "time" "github.com/aler9/gortsplib" @@ -110,7 +109,6 @@ func New( terminate: make(chan struct{}), } - atomic.AddInt64(c.stats.CountClients, 1) c.log(logger.Info, "connected") c.wg.Add(1) @@ -121,7 +119,6 @@ func New( // Close closes a Client. func (c *Client) Close() { - atomic.AddInt64(c.stats.CountClients, -1) c.log(logger.Info, "disconnected") close(c.terminate) } diff --git a/internal/clientrtsp/client.go b/internal/clientrtsp/client.go index 1aed3a4f..dc3ff481 100644 --- a/internal/clientrtsp/client.go +++ b/internal/clientrtsp/client.go @@ -4,7 +4,6 @@ import ( "errors" "io" "net" - "sync/atomic" "time" "github.com/aler9/gortsplib" @@ -79,7 +78,6 @@ func New( parent: parent, } - atomic.AddInt64(c.stats.CountClients, 1) c.log(logger.Info, "connected") if c.runOnConnect != "" { @@ -99,7 +97,6 @@ func (c *Client) Close(err error) { c.log(logger.Info, "ERR: %v", err) } - atomic.AddInt64(c.stats.CountClients, -1) c.log(logger.Info, "disconnected") if c.onConnectCmd != nil { diff --git a/internal/converterhls/converter.go b/internal/converterhls/converter.go index 9534a939..4fbb3007 100644 --- a/internal/converterhls/converter.go +++ b/internal/converterhls/converter.go @@ -480,7 +480,6 @@ func (c *Converter) run() { case <-closeCheckTicker.C: t := time.Unix(atomic.LoadInt64(&c.lastRequestTime), 0) if time.Since(t) >= closeAfterInactivity { - c.log(logger.Info, "destroying due to inactivity") c.ringBuffer.Close() <-writerDone diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 02b15ae8..a238abed 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -77,7 +77,6 @@ func (m *Metrics) run() { func (m *Metrics) onMetrics(w http.ResponseWriter, req *http.Request) { nowUnix := time.Now().UnixNano() / 1000000 - countClients := atomic.LoadInt64(m.stats.CountClients) countPublishers := atomic.LoadInt64(m.stats.CountPublishers) countReaders := atomic.LoadInt64(m.stats.CountReaders) countSourcesRTSP := atomic.LoadInt64(m.stats.CountSourcesRTSP) @@ -86,16 +85,17 @@ func (m *Metrics) onMetrics(w http.ResponseWriter, req *http.Request) { countSourcesRTMPRunning := atomic.LoadInt64(m.stats.CountSourcesRTMPRunning) out := "" - out += formatMetric("rtsp_clients{state=\"idle\"}", - countClients-countPublishers-countReaders, nowUnix) + out += formatMetric("rtsp_clients{state=\"publishing\"}", countPublishers, nowUnix) out += formatMetric("rtsp_clients{state=\"reading\"}", countReaders, nowUnix) + out += formatMetric("rtsp_sources{type=\"rtsp\",state=\"idle\"}", countSourcesRTSP-countSourcesRTSPRunning, nowUnix) out += formatMetric("rtsp_sources{type=\"rtsp\",state=\"running\"}", countSourcesRTSPRunning, nowUnix) + out += formatMetric("rtsp_sources{type=\"rtmp\",state=\"idle\"}", countSourcesRTMP-countSourcesRTMPRunning, nowUnix) out += formatMetric("rtsp_sources{type=\"rtmp\",state=\"running\"}", diff --git a/internal/sessionrtsp/session.go b/internal/sessionrtsp/session.go index ea9bbd10..cd89daf4 100644 --- a/internal/sessionrtsp/session.go +++ b/internal/sessionrtsp/session.go @@ -77,8 +77,6 @@ func New( // Close closes a Session. func (s *Session) Close() { - s.log(logger.Info, "destroyed") - switch s.ss.State() { case gortsplib.ServerSessionStatePlay: if s.onReadCmd != nil { @@ -97,6 +95,8 @@ func (s *Session) Close() { <-res s.path = nil } + + s.log(logger.Info, "destroyed") } // RequestClose closes a Session. diff --git a/internal/stats/stats.go b/internal/stats/stats.go index b4369bcd..1975eeb6 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -9,7 +9,6 @@ func ptrInt64() *int64 { type Stats struct { // use pointers to avoid a crash on 32bit platforms // https://github.com/golang/go/issues/9959 - CountClients *int64 CountPublishers *int64 CountReaders *int64 CountSourcesRTSP *int64 @@ -21,7 +20,6 @@ type Stats struct { // New allocates a Stats. func New() *Stats { return &Stats{ - CountClients: ptrInt64(), CountPublishers: ptrInt64(), CountReaders: ptrInt64(), CountSourcesRTSP: ptrInt64(), diff --git a/main.go b/main.go index c20cb03a..f22cb61a 100644 --- a/main.go +++ b/main.go @@ -102,11 +102,10 @@ func (p *program) close() { } func (p *program) Log(level logger.Level, format string, args ...interface{}) { - countClients := atomic.LoadInt64(p.stats.CountClients) countPublishers := atomic.LoadInt64(p.stats.CountPublishers) countReaders := atomic.LoadInt64(p.stats.CountReaders) - p.logger.Log(level, "[%d/%d/%d] "+format, append([]interface{}{countClients, + p.logger.Log(level, "[%d/%d] "+format, append([]interface{}{ countPublishers, countReaders}, args...)...) }