mirror of
https://github.com/bluenviron/mediamtx
synced 2025-02-18 12:36:56 +00:00
apply listenIP to metrics and pprof too
This commit is contained in:
parent
9b052f1cdc
commit
903842484e
@ -64,7 +64,7 @@ Download and launch the image:
|
|||||||
docker run --rm -it --network=host aler9/rtsp-simple-server
|
docker run --rm -it --network=host aler9/rtsp-simple-server
|
||||||
```
|
```
|
||||||
|
|
||||||
The `--network=host` flag is mandatory since Docker can change the source port of UDP packets for routing reasons, and this makes impossible finding out the publisher of the packets. This issue can be avoided by disabling UDP and exposing the RTSP port:
|
The `--network=host` flag is mandatory since Docker can change the source port of UDP packets for routing reasons, and this doesn't allow to find out the publisher of the packets. This issue can be avoided by disabling UDP and exposing the RTSP port:
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server
|
docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server
|
||||||
@ -131,7 +131,7 @@ There are two ways to change the configuration:
|
|||||||
RTSP_PATHS_TEST_SOURCE=rtsp://myurl ./rtsp-simple-server
|
RTSP_PATHS_TEST_SOURCE=rtsp://myurl ./rtsp-simple-server
|
||||||
```
|
```
|
||||||
|
|
||||||
This method is particularly useful when running rtsp-simple-server with Docker; any configuration parameter can be changed by passing environment variables with the `-e` flag:
|
This method is particularly useful when using Docker; any configuration parameter can be changed by passing environment variables with the `-e` flag:
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run --rm -it --network=host -e RTSP_PATHS_TEST_SOURCE=rtsp://myurl aler9/rtsp-simple-server
|
docker run --rm -it --network=host -e RTSP_PATHS_TEST_SOURCE=rtsp://myurl aler9/rtsp-simple-server
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
address = ":9998"
|
port = 9998
|
||||||
)
|
)
|
||||||
|
|
||||||
func formatMetric(key string, value int64, nowUnix int64) string {
|
func formatMetric(key string, value int64, nowUnix int64) string {
|
||||||
@ -37,7 +37,13 @@ type Metrics struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New allocates a metrics.
|
// New allocates a metrics.
|
||||||
func New(stats *stats.Stats, parent Parent) (*Metrics, error) {
|
func New(
|
||||||
|
listenIP string,
|
||||||
|
stats *stats.Stats,
|
||||||
|
parent Parent,
|
||||||
|
) (*Metrics, error) {
|
||||||
|
|
||||||
|
address := listenIP + ":" + strconv.FormatInt(port, 10)
|
||||||
listener, err := net.Listen("tcp", address)
|
listener, err := net.Listen("tcp", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
// start pprof
|
// start pprof
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
address = ":9999"
|
port = 9999
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parent is implemented by program.
|
// Parent is implemented by program.
|
||||||
@ -27,7 +28,11 @@ type Pprof struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New allocates a Pprof.
|
// New allocates a Pprof.
|
||||||
func New(parent Parent) (*Pprof, error) {
|
func New(
|
||||||
|
listenIP string,
|
||||||
|
parent Parent,
|
||||||
|
) (*Pprof, error) {
|
||||||
|
address := listenIP + ":" + strconv.FormatInt(port, 10)
|
||||||
listener, err := net.Listen("tcp", address)
|
listener, err := net.Listen("tcp", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
15
main.go
15
main.go
@ -164,7 +164,10 @@ func (p *program) createResources(initial bool) error {
|
|||||||
|
|
||||||
if p.conf.Metrics {
|
if p.conf.Metrics {
|
||||||
if p.metrics == nil {
|
if p.metrics == nil {
|
||||||
p.metrics, err = metrics.New(p.stats, p)
|
p.metrics, err = metrics.New(
|
||||||
|
p.conf.ListenIP,
|
||||||
|
p.stats,
|
||||||
|
p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -173,7 +176,9 @@ func (p *program) createResources(initial bool) error {
|
|||||||
|
|
||||||
if p.conf.Pprof {
|
if p.conf.Pprof {
|
||||||
if p.pprof == nil {
|
if p.pprof == nil {
|
||||||
p.pprof, err = pprof.New(p)
|
p.pprof, err = pprof.New(
|
||||||
|
p.conf.ListenIP,
|
||||||
|
p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -277,13 +282,15 @@ func (p *program) closeResources(newConf *conf.Conf) {
|
|||||||
|
|
||||||
closeMetrics := false
|
closeMetrics := false
|
||||||
if newConf == nil ||
|
if newConf == nil ||
|
||||||
newConf.Metrics != p.conf.Metrics {
|
newConf.Metrics != p.conf.Metrics ||
|
||||||
|
newConf.ListenIP != p.conf.ListenIP {
|
||||||
closeMetrics = true
|
closeMetrics = true
|
||||||
}
|
}
|
||||||
|
|
||||||
closePprof := false
|
closePprof := false
|
||||||
if newConf == nil ||
|
if newConf == nil ||
|
||||||
newConf.Pprof != p.conf.Pprof {
|
newConf.Pprof != p.conf.Pprof ||
|
||||||
|
newConf.ListenIP != p.conf.ListenIP {
|
||||||
closePprof = true
|
closePprof = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user