apply listenIP to metrics and pprof too

This commit is contained in:
aler9 2021-01-15 18:56:35 +01:00
parent 9b052f1cdc
commit 903842484e
4 changed files with 28 additions and 10 deletions

View File

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

View File

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

View File

@ -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
View File

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