mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-15 03:04:45 +00:00
remove number of clients from logs
This commit is contained in:
parent
8531fc49dc
commit
4d260412c4
@ -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:
|
* 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:
|
* 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:
|
Obtaining:
|
||||||
|
|
||||||
```
|
```
|
||||||
rtsp_clients{state="idle"} 2 1596122687740
|
|
||||||
rtsp_clients{state="publishing"} 15 1596122687740
|
rtsp_clients{state="publishing"} 15 1596122687740
|
||||||
rtsp_clients{state="reading"} 8 1596122687740
|
rtsp_clients{state="reading"} 8 1596122687740
|
||||||
rtsp_sources{type="rtsp",state="idle"} 3 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:
|
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="publishing"}` is the count of clients that are publishing
|
||||||
* `rtsp_clients{state="reading"}` is the count of clients that are reading
|
* `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
|
* `rtsp_sources{type="rtsp",state="idle"}` is the count of rtsp sources that are not running
|
||||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.15
|
|||||||
require (
|
require (
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // 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/asticode/go-astits v0.0.0-00010101000000-000000000000
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.4.9
|
github.com/fsnotify/fsnotify v1.4.9
|
||||||
|
4
go.sum
4
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/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 h1:CXgQLsU4uxWAmsXNOjGLbj0A+0IlRcpZpMgI13fmVwo=
|
||||||
github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ=
|
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-20210508203529-1b9b19dd8493 h1:fyc2te2rF8JIRuft//GORUYH6UYfQCKuiaoEmM0JCEc=
|
||||||
github.com/aler9/gortsplib v0.0.0-20210508202705-7469a3362a7d/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY=
|
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 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ=
|
||||||
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc=
|
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=
|
github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib"
|
"github.com/aler9/gortsplib"
|
||||||
@ -110,7 +109,6 @@ func New(
|
|||||||
terminate: make(chan struct{}),
|
terminate: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.AddInt64(c.stats.CountClients, 1)
|
|
||||||
c.log(logger.Info, "connected")
|
c.log(logger.Info, "connected")
|
||||||
|
|
||||||
c.wg.Add(1)
|
c.wg.Add(1)
|
||||||
@ -121,7 +119,6 @@ func New(
|
|||||||
|
|
||||||
// Close closes a Client.
|
// Close closes a Client.
|
||||||
func (c *Client) Close() {
|
func (c *Client) Close() {
|
||||||
atomic.AddInt64(c.stats.CountClients, -1)
|
|
||||||
c.log(logger.Info, "disconnected")
|
c.log(logger.Info, "disconnected")
|
||||||
close(c.terminate)
|
close(c.terminate)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib"
|
"github.com/aler9/gortsplib"
|
||||||
@ -79,7 +78,6 @@ func New(
|
|||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.AddInt64(c.stats.CountClients, 1)
|
|
||||||
c.log(logger.Info, "connected")
|
c.log(logger.Info, "connected")
|
||||||
|
|
||||||
if c.runOnConnect != "" {
|
if c.runOnConnect != "" {
|
||||||
@ -99,7 +97,6 @@ func (c *Client) Close(err error) {
|
|||||||
c.log(logger.Info, "ERR: %v", err)
|
c.log(logger.Info, "ERR: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.AddInt64(c.stats.CountClients, -1)
|
|
||||||
c.log(logger.Info, "disconnected")
|
c.log(logger.Info, "disconnected")
|
||||||
|
|
||||||
if c.onConnectCmd != nil {
|
if c.onConnectCmd != nil {
|
||||||
|
@ -480,7 +480,6 @@ func (c *Converter) run() {
|
|||||||
case <-closeCheckTicker.C:
|
case <-closeCheckTicker.C:
|
||||||
t := time.Unix(atomic.LoadInt64(&c.lastRequestTime), 0)
|
t := time.Unix(atomic.LoadInt64(&c.lastRequestTime), 0)
|
||||||
if time.Since(t) >= closeAfterInactivity {
|
if time.Since(t) >= closeAfterInactivity {
|
||||||
c.log(logger.Info, "destroying due to inactivity")
|
|
||||||
|
|
||||||
c.ringBuffer.Close()
|
c.ringBuffer.Close()
|
||||||
<-writerDone
|
<-writerDone
|
||||||
|
@ -77,7 +77,6 @@ func (m *Metrics) run() {
|
|||||||
func (m *Metrics) onMetrics(w http.ResponseWriter, req *http.Request) {
|
func (m *Metrics) onMetrics(w http.ResponseWriter, req *http.Request) {
|
||||||
nowUnix := time.Now().UnixNano() / 1000000
|
nowUnix := time.Now().UnixNano() / 1000000
|
||||||
|
|
||||||
countClients := atomic.LoadInt64(m.stats.CountClients)
|
|
||||||
countPublishers := atomic.LoadInt64(m.stats.CountPublishers)
|
countPublishers := atomic.LoadInt64(m.stats.CountPublishers)
|
||||||
countReaders := atomic.LoadInt64(m.stats.CountReaders)
|
countReaders := atomic.LoadInt64(m.stats.CountReaders)
|
||||||
countSourcesRTSP := atomic.LoadInt64(m.stats.CountSourcesRTSP)
|
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)
|
countSourcesRTMPRunning := atomic.LoadInt64(m.stats.CountSourcesRTMPRunning)
|
||||||
|
|
||||||
out := ""
|
out := ""
|
||||||
out += formatMetric("rtsp_clients{state=\"idle\"}",
|
|
||||||
countClients-countPublishers-countReaders, nowUnix)
|
|
||||||
out += formatMetric("rtsp_clients{state=\"publishing\"}",
|
out += formatMetric("rtsp_clients{state=\"publishing\"}",
|
||||||
countPublishers, nowUnix)
|
countPublishers, nowUnix)
|
||||||
out += formatMetric("rtsp_clients{state=\"reading\"}",
|
out += formatMetric("rtsp_clients{state=\"reading\"}",
|
||||||
countReaders, nowUnix)
|
countReaders, nowUnix)
|
||||||
|
|
||||||
out += formatMetric("rtsp_sources{type=\"rtsp\",state=\"idle\"}",
|
out += formatMetric("rtsp_sources{type=\"rtsp\",state=\"idle\"}",
|
||||||
countSourcesRTSP-countSourcesRTSPRunning, nowUnix)
|
countSourcesRTSP-countSourcesRTSPRunning, nowUnix)
|
||||||
out += formatMetric("rtsp_sources{type=\"rtsp\",state=\"running\"}",
|
out += formatMetric("rtsp_sources{type=\"rtsp\",state=\"running\"}",
|
||||||
countSourcesRTSPRunning, nowUnix)
|
countSourcesRTSPRunning, nowUnix)
|
||||||
|
|
||||||
out += formatMetric("rtsp_sources{type=\"rtmp\",state=\"idle\"}",
|
out += formatMetric("rtsp_sources{type=\"rtmp\",state=\"idle\"}",
|
||||||
countSourcesRTMP-countSourcesRTMPRunning, nowUnix)
|
countSourcesRTMP-countSourcesRTMPRunning, nowUnix)
|
||||||
out += formatMetric("rtsp_sources{type=\"rtmp\",state=\"running\"}",
|
out += formatMetric("rtsp_sources{type=\"rtmp\",state=\"running\"}",
|
||||||
|
@ -77,8 +77,6 @@ func New(
|
|||||||
|
|
||||||
// Close closes a Session.
|
// Close closes a Session.
|
||||||
func (s *Session) Close() {
|
func (s *Session) Close() {
|
||||||
s.log(logger.Info, "destroyed")
|
|
||||||
|
|
||||||
switch s.ss.State() {
|
switch s.ss.State() {
|
||||||
case gortsplib.ServerSessionStatePlay:
|
case gortsplib.ServerSessionStatePlay:
|
||||||
if s.onReadCmd != nil {
|
if s.onReadCmd != nil {
|
||||||
@ -97,6 +95,8 @@ func (s *Session) Close() {
|
|||||||
<-res
|
<-res
|
||||||
s.path = nil
|
s.path = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.log(logger.Info, "destroyed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestClose closes a Session.
|
// RequestClose closes a Session.
|
||||||
|
@ -9,7 +9,6 @@ func ptrInt64() *int64 {
|
|||||||
type Stats struct {
|
type Stats struct {
|
||||||
// use pointers to avoid a crash on 32bit platforms
|
// use pointers to avoid a crash on 32bit platforms
|
||||||
// https://github.com/golang/go/issues/9959
|
// https://github.com/golang/go/issues/9959
|
||||||
CountClients *int64
|
|
||||||
CountPublishers *int64
|
CountPublishers *int64
|
||||||
CountReaders *int64
|
CountReaders *int64
|
||||||
CountSourcesRTSP *int64
|
CountSourcesRTSP *int64
|
||||||
@ -21,7 +20,6 @@ type Stats struct {
|
|||||||
// New allocates a Stats.
|
// New allocates a Stats.
|
||||||
func New() *Stats {
|
func New() *Stats {
|
||||||
return &Stats{
|
return &Stats{
|
||||||
CountClients: ptrInt64(),
|
|
||||||
CountPublishers: ptrInt64(),
|
CountPublishers: ptrInt64(),
|
||||||
CountReaders: ptrInt64(),
|
CountReaders: ptrInt64(),
|
||||||
CountSourcesRTSP: ptrInt64(),
|
CountSourcesRTSP: ptrInt64(),
|
||||||
|
3
main.go
3
main.go
@ -102,11 +102,10 @@ func (p *program) close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *program) Log(level logger.Level, format string, args ...interface{}) {
|
func (p *program) Log(level logger.Level, format string, args ...interface{}) {
|
||||||
countClients := atomic.LoadInt64(p.stats.CountClients)
|
|
||||||
countPublishers := atomic.LoadInt64(p.stats.CountPublishers)
|
countPublishers := atomic.LoadInt64(p.stats.CountPublishers)
|
||||||
countReaders := atomic.LoadInt64(p.stats.CountReaders)
|
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...)...)
|
countPublishers, countReaders}, args...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user