diff --git a/README.md b/README.md index c73a693adb1..0a0186375fc 100644 --- a/README.md +++ b/README.md @@ -1433,6 +1433,7 @@ Obtaining: # metrics of every path paths{name="[path_name]",state="[state]"} 1 paths_bytes_received{name="[path_name]",state="[state]"} 1234 +paths_bytes_sent{name="[path_name]",state="[state]"} 1234 # metrics of every HLS muxer hls_muxers{name="[name]"} 1 @@ -1463,6 +1464,11 @@ rtmp_conns{id="[id]",state="[state]"} 1 rtmp_conns_bytes_received{id="[id]",state="[state]"} 1234 rtmp_conns_bytes_sent{id="[id]",state="[state]"} 187 +# metrics of every SRT connection +srt_conns{id="[id]",state="[state]"} 1 +srt_conns_bytes_received{id="[id]",state="[state]"} 1234 +srt_conns_bytes_sent{id="[id]",state="[state]"} 187 + # metrics of every WebRTC session webrtc_sessions{id="[id]"} 1 webrtc_sessions_bytes_received{id="[id]",state="[state]"} 1234 diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index c03442ce863..26e37467c26 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -393,6 +393,9 @@ components: bytesReceived: type: integer format: int64 + bytesSent: + type: integer + format: int64 readers: type: array items: diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 05278bce0ae..7964c8cac40 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -422,6 +422,7 @@ func TestAPIPathsList(t *testing.T) { Ready bool `json:"ready"` Tracks []string `json:"tracks"` BytesReceived uint64 `json:"bytesReceived"` + BytesSent uint64 `json:"bytesSent"` } type pathList struct { @@ -625,6 +626,7 @@ func TestAPIPathsGet(t *testing.T) { Ready bool `json:"Ready"` Tracks []string `json:"tracks"` BytesReceived uint64 `json:"bytesReceived"` + BytesSent uint64 `json:"bytesSent"` } var pathName string diff --git a/internal/core/core.go b/internal/core/core.go index 793351acf63..c9d21fee6e6 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -509,6 +509,7 @@ func (p *Core) createResources(initial bool) error { p.conf.RunOnConnectRestart, p.conf.RunOnDisconnect, p.externalCmdPool, + p.metrics, p.pathManager, p, ) diff --git a/internal/core/metrics.go b/internal/core/metrics.go index 1b3460f8533..8ff2132a825 100644 --- a/internal/core/metrics.go +++ b/internal/core/metrics.go @@ -32,6 +32,7 @@ type metrics struct { rtspServer apiRTSPServer rtspsServer apiRTSPServer rtmpServer apiRTMPServer + srtServer apiSRTServer hlsManager apiHLSManager webRTCManager apiWebRTCManager } @@ -96,6 +97,7 @@ func (m *metrics) onMetrics(ctx *gin.Context) { tags := "{name=\"" + i.Name + "\",state=\"" + state + "\"}" out += metric("paths", tags, 1) out += metric("paths_bytes_received", tags, int64(i.BytesReceived)) + out += metric("paths_bytes_sent", tags, int64(i.BytesSent)) } } else { out += metric("paths", "", 0) @@ -199,6 +201,22 @@ func (m *metrics) onMetrics(ctx *gin.Context) { } } + if !interfaceIsEmpty(m.srtServer) { + data, err := m.srtServer.apiConnsList() + if err == nil && len(data.Items) != 0 { + for _, i := range data.Items { + tags := "{id=\"" + i.ID.String() + "\",state=\"" + string(i.State) + "\"}" + out += metric("srt_conns", tags, 1) + out += metric("srt_conns_bytes_received", tags, int64(i.BytesReceived)) + out += metric("srt_conns_bytes_sent", tags, int64(i.BytesSent)) + } + } else { + out += metric("srt_conns", "", 0) + out += metric("srt_conns_bytes_received", "", 0) + out += metric("srt_conns_bytes_sent", "", 0) + } + } + if !interfaceIsEmpty(m.webRTCManager) { data, err := m.webRTCManager.apiSessionsList() if err == nil && len(data.Items) != 0 { @@ -254,6 +272,13 @@ func (m *metrics) rtmpServerSet(s apiRTMPServer) { m.rtmpServer = s } +// srtServerSet is called by srtServer. +func (m *metrics) srtServerSet(s apiSRTServer) { + m.mutex.Lock() + defer m.mutex.Unlock() + m.srtServer = s +} + // webRTCManagerSet is called by webRTCManager. func (m *metrics) webRTCManagerSet(s apiWebRTCManager) { m.mutex.Lock() diff --git a/internal/core/path.go b/internal/core/path.go index 7b57a94db07..283939efa69 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -754,6 +754,12 @@ func (pa *path) doAPIPathsGet(req pathAPIPathsGetReq) { } return pa.stream.BytesReceived() }(), + BytesSent: func() uint64 { + if pa.stream == nil { + return 0 + } + return pa.stream.BytesSent() + }(), Readers: func() []defs.APIPathSourceOrReader { ret := []defs.APIPathSourceOrReader{} for r := range pa.readers { diff --git a/internal/core/srt_server.go b/internal/core/srt_server.go index 2c482d13c02..b8876323563 100644 --- a/internal/core/srt_server.go +++ b/internal/core/srt_server.go @@ -67,6 +67,7 @@ type srtServer struct { runOnConnectRestart bool runOnDisconnect string externalCmdPool *externalcmd.Pool + metrics *metrics pathManager *pathManager parent srtServerParent @@ -96,6 +97,7 @@ func newSRTServer( runOnConnectRestart bool, runOnDisconnect string, externalCmdPool *externalcmd.Pool, + metrics *metrics, pathManager *pathManager, parent srtServerParent, ) (*srtServer, error) { @@ -120,6 +122,7 @@ func newSRTServer( runOnConnectRestart: runOnConnectRestart, runOnDisconnect: runOnDisconnect, externalCmdPool: externalCmdPool, + metrics: metrics, pathManager: pathManager, parent: parent, ctx: ctx, @@ -136,6 +139,10 @@ func newSRTServer( s.Log(logger.Info, "listener opened on "+address+" (UDP)") + if s.metrics != nil { + s.metrics.srtServerSet(s) + } + newSRTListener( s.ln, &s.wg, diff --git a/internal/core/static_source_handler.go b/internal/core/static_source_handler.go index 34184cd82ff..cec9961e494 100644 --- a/internal/core/static_source_handler.go +++ b/internal/core/static_source_handler.go @@ -83,8 +83,7 @@ func newStaticSourceHandler( case strings.HasPrefix(cnf.Source, "http://") || strings.HasPrefix(cnf.Source, "https://"): s.instance = &hlssource.Source{ - ReadTimeout: readTimeout, - Parent: s, + Parent: s, } case strings.HasPrefix(cnf.Source, "udp://"): diff --git a/internal/core/webrtc_publish_index.html b/internal/core/webrtc_publish_index.html index 0edc3304aae..3ab63c261c1 100644 --- a/internal/core/webrtc_publish_index.html +++ b/internal/core/webrtc_publish_index.html @@ -26,27 +26,21 @@ justify-content: center; min-height: 200px; padding: 10px; - flex-direction: column; } - #device { - display: grid; - grid-template-rows: repeat(6, 1fr); - grid-auto-flow: column; - gap: 10px 20px + flex-direction: column; } - -.item { - display: grid; - grid-auto-flow: column; - grid-template-columns: auto 200px; +#device > div { + margin: 10px 0; + display: flex; gap: 20px; + justify-content: center; + flex-wrap: wrap; } - -#submit_line { - margin-top: 20px; +#device > div > div { + display: flex; + gap: 20px; } - #error-message { text-align: center; } @@ -62,81 +56,65 @@
initializing
- -