Browse Source

add parameter pprofPort to configure the port of the pprof listener

pull/340/head
aler9 5 years ago
parent
commit
a57f3d04a7
  1. 5
      internal/conf/conf.go
  2. 7
      internal/pprof/pprof.go
  3. 4
      main.go
  4. 4
      rtsp-simple-server.yml

5
internal/conf/conf.go

@ -60,6 +60,7 @@ type Conf struct { @@ -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 { @@ -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"}
}

7
internal/pprof/pprof.go

@ -12,10 +12,6 @@ import ( @@ -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 { @@ -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

4
main.go

@ -183,6 +183,7 @@ func (p *program) createResources(initial bool) error { @@ -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) { @@ -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
}

4
rtsp-simple-server.yml

@ -25,8 +25,10 @@ metrics: no @@ -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.

Loading…
Cancel
Save