From a57f3d04a7c44d58a78a83eabb09736129c8188c Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 27 Mar 2021 11:21:30 +0100 Subject: [PATCH] add parameter pprofPort to configure the port of the pprof listener --- internal/conf/conf.go | 5 +++++ internal/pprof/pprof.go | 7 ++----- main.go | 4 +++- rtsp-simple-server.yml | 4 +++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/conf/conf.go b/internal/conf/conf.go index ac34df8b..ded26546 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -60,6 +60,7 @@ type Conf struct { Metrics bool `yaml:"metrics"` MetricsPort int `yaml:"metricsPort"` Pprof bool `yaml:"pprof"` + PprofPort int `yaml:"pprofPort"` RunOnConnect string `yaml:"runOnConnect"` RunOnConnectRestart bool `yaml:"runOnConnectRestart"` @@ -142,6 +143,10 @@ func (conf *Conf) fillAndCheck() error { conf.MetricsPort = 9998 } + if conf.PprofPort == 0 { + conf.MetricsPort = 9999 + } + if len(conf.Protocols) == 0 { conf.Protocols = []string{"udp", "tcp"} } diff --git a/internal/pprof/pprof.go b/internal/pprof/pprof.go index 29ee6eba..98818939 100644 --- a/internal/pprof/pprof.go +++ b/internal/pprof/pprof.go @@ -12,10 +12,6 @@ import ( "github.com/aler9/rtsp-simple-server/internal/logger" ) -const ( - port = 9999 -) - // Parent is implemented by program. type Parent interface { Log(logger.Level, string, ...interface{}) @@ -30,9 +26,10 @@ type Pprof struct { // New allocates a Pprof. func New( listenIP string, + port int, parent Parent, ) (*Pprof, error) { - address := listenIP + ":" + strconv.FormatInt(port, 10) + address := listenIP + ":" + strconv.FormatInt(int64(port), 10) listener, err := net.Listen("tcp", address) if err != nil { return nil, err diff --git a/main.go b/main.go index 7eb8867c..70db1dc7 100644 --- a/main.go +++ b/main.go @@ -183,6 +183,7 @@ func (p *program) createResources(initial bool) error { if p.pprof == nil { p.pprof, err = pprof.New( p.conf.ListenIP, + p.conf.PprofPort, p) if err != nil { return err @@ -303,7 +304,8 @@ func (p *program) closeResources(newConf *conf.Conf) { closePprof := false if newConf == nil || newConf.Pprof != p.conf.Pprof || - newConf.ListenIP != p.conf.ListenIP { + newConf.ListenIP != p.conf.ListenIP || + newConf.PprofPort != p.conf.PprofPort { closePprof = true } diff --git a/rtsp-simple-server.yml b/rtsp-simple-server.yml index b47de286..1a6d3410 100644 --- a/rtsp-simple-server.yml +++ b/rtsp-simple-server.yml @@ -25,8 +25,10 @@ metrics: no # port of the metrics listener. metricsPort: 9998 -# enable pprof on port 9999 to monitor performances. +# enable pprof to monitor performances. pprof: no +# port of the pprof listener. +pprofPort: 9999 # command to run when a client connects to the server. # this is terminated with SIGINT when a client disconnects from the server.