mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-05 23:56:54 +08:00
add parameter pprofPort to configure the port of the pprof listener
This commit is contained in:
@@ -60,6 +60,7 @@ type Conf struct {
|
|||||||
Metrics bool `yaml:"metrics"`
|
Metrics bool `yaml:"metrics"`
|
||||||
MetricsPort int `yaml:"metricsPort"`
|
MetricsPort int `yaml:"metricsPort"`
|
||||||
Pprof bool `yaml:"pprof"`
|
Pprof bool `yaml:"pprof"`
|
||||||
|
PprofPort int `yaml:"pprofPort"`
|
||||||
RunOnConnect string `yaml:"runOnConnect"`
|
RunOnConnect string `yaml:"runOnConnect"`
|
||||||
RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
|
RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
|
||||||
|
|
||||||
@@ -142,6 +143,10 @@ func (conf *Conf) fillAndCheck() error {
|
|||||||
conf.MetricsPort = 9998
|
conf.MetricsPort = 9998
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.PprofPort == 0 {
|
||||||
|
conf.MetricsPort = 9999
|
||||||
|
}
|
||||||
|
|
||||||
if len(conf.Protocols) == 0 {
|
if len(conf.Protocols) == 0 {
|
||||||
conf.Protocols = []string{"udp", "tcp"}
|
conf.Protocols = []string{"udp", "tcp"}
|
||||||
}
|
}
|
||||||
|
@@ -12,10 +12,6 @@ import (
|
|||||||
"github.com/aler9/rtsp-simple-server/internal/logger"
|
"github.com/aler9/rtsp-simple-server/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
port = 9999
|
|
||||||
)
|
|
||||||
|
|
||||||
// Parent is implemented by program.
|
// Parent is implemented by program.
|
||||||
type Parent interface {
|
type Parent interface {
|
||||||
Log(logger.Level, string, ...interface{})
|
Log(logger.Level, string, ...interface{})
|
||||||
@@ -30,9 +26,10 @@ type Pprof struct {
|
|||||||
// New allocates a Pprof.
|
// New allocates a Pprof.
|
||||||
func New(
|
func New(
|
||||||
listenIP string,
|
listenIP string,
|
||||||
|
port int,
|
||||||
parent Parent,
|
parent Parent,
|
||||||
) (*Pprof, error) {
|
) (*Pprof, error) {
|
||||||
address := listenIP + ":" + strconv.FormatInt(port, 10)
|
address := listenIP + ":" + strconv.FormatInt(int64(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
main.go
4
main.go
@@ -183,6 +183,7 @@ func (p *program) createResources(initial bool) error {
|
|||||||
if p.pprof == nil {
|
if p.pprof == nil {
|
||||||
p.pprof, err = pprof.New(
|
p.pprof, err = pprof.New(
|
||||||
p.conf.ListenIP,
|
p.conf.ListenIP,
|
||||||
|
p.conf.PprofPort,
|
||||||
p)
|
p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -303,7 +304,8 @@ func (p *program) closeResources(newConf *conf.Conf) {
|
|||||||
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 {
|
newConf.ListenIP != p.conf.ListenIP ||
|
||||||
|
newConf.PprofPort != p.conf.PprofPort {
|
||||||
closePprof = true
|
closePprof = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,8 +25,10 @@ metrics: no
|
|||||||
# port of the metrics listener.
|
# port of the metrics listener.
|
||||||
metricsPort: 9998
|
metricsPort: 9998
|
||||||
|
|
||||||
# enable pprof on port 9999 to monitor performances.
|
# enable pprof to monitor performances.
|
||||||
pprof: no
|
pprof: no
|
||||||
|
# port of the pprof listener.
|
||||||
|
pprofPort: 9999
|
||||||
|
|
||||||
# command to run when a client connects to the server.
|
# command to run when a client connects to the server.
|
||||||
# this is terminated with SIGINT when a client disconnects from the server.
|
# this is terminated with SIGINT when a client disconnects from the server.
|
||||||
|
Reference in New Issue
Block a user