forked from External/mediamtx
add ability to configure metrics port
Port could be specified by using either metricsPort config file entry or RTSP_METRICSPORT environment variable.
This commit is contained in:
parent
0dff484ff5
commit
c1862b3228
4 changed files with 14 additions and 7 deletions
|
|
@ -58,6 +58,7 @@ type Conf struct {
|
||||||
WriteTimeout time.Duration `yaml:"writeTimeout"`
|
WriteTimeout time.Duration `yaml:"writeTimeout"`
|
||||||
ReadBufferCount int `yaml:"readBufferCount"`
|
ReadBufferCount int `yaml:"readBufferCount"`
|
||||||
Metrics bool `yaml:"metrics"`
|
Metrics bool `yaml:"metrics"`
|
||||||
|
MetricsPort int `yaml:"metricsPort"`
|
||||||
Pprof bool `yaml:"pprof"`
|
Pprof bool `yaml:"pprof"`
|
||||||
RunOnConnect string `yaml:"runOnConnect"`
|
RunOnConnect string `yaml:"runOnConnect"`
|
||||||
RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
|
RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
|
||||||
|
|
@ -137,6 +138,10 @@ func (conf *Conf) fillAndCheck() error {
|
||||||
conf.ReadBufferCount = 512
|
conf.ReadBufferCount = 512
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.MetricsPort == 0 {
|
||||||
|
conf.MetricsPort = 9998
|
||||||
|
}
|
||||||
|
|
||||||
if len(conf.Protocols) == 0 {
|
if len(conf.Protocols) == 0 {
|
||||||
conf.Protocols = []string{"udp", "tcp"}
|
conf.Protocols = []string{"udp", "tcp"}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,6 @@ import (
|
||||||
"github.com/aler9/rtsp-simple-server/internal/stats"
|
"github.com/aler9/rtsp-simple-server/internal/stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
port = 9998
|
|
||||||
)
|
|
||||||
|
|
||||||
func formatMetric(key string, value int64, nowUnix int64) string {
|
func formatMetric(key string, value int64, nowUnix int64) string {
|
||||||
return key + " " + strconv.FormatInt(value, 10) + " " +
|
return key + " " + strconv.FormatInt(value, 10) + " " +
|
||||||
strconv.FormatInt(nowUnix, 10) + "\n"
|
strconv.FormatInt(nowUnix, 10) + "\n"
|
||||||
|
|
@ -39,11 +35,12 @@ type Metrics struct {
|
||||||
// New allocates a metrics.
|
// New allocates a metrics.
|
||||||
func New(
|
func New(
|
||||||
listenIP string,
|
listenIP string,
|
||||||
|
port int,
|
||||||
stats *stats.Stats,
|
stats *stats.Stats,
|
||||||
parent Parent,
|
parent Parent,
|
||||||
) (*Metrics, error) {
|
) (*Metrics, 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
|
|
@ -164,6 +164,7 @@ func (p *program) createResources(initial bool) error {
|
||||||
if p.metrics == nil {
|
if p.metrics == nil {
|
||||||
p.metrics, err = metrics.New(
|
p.metrics, err = metrics.New(
|
||||||
p.conf.ListenIP,
|
p.conf.ListenIP,
|
||||||
|
p.conf.MetricsPort,
|
||||||
p.stats,
|
p.stats,
|
||||||
p)
|
p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -288,7 +289,8 @@ 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 {
|
newConf.ListenIP != p.conf.ListenIP ||
|
||||||
|
newConf.MetricsPort != p.conf.MetricsPort {
|
||||||
closeMetrics = true
|
closeMetrics = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,11 @@ writeTimeout: 10s
|
||||||
# a lower number allows to save RAM.
|
# a lower number allows to save RAM.
|
||||||
readBufferCount: 512
|
readBufferCount: 512
|
||||||
|
|
||||||
# enable Prometheus-compatible metrics on port 9998.
|
# enable Prometheus-compatible metrics.
|
||||||
metrics: no
|
metrics: no
|
||||||
|
# port of the metrics listener.
|
||||||
|
metricsPort: 9998
|
||||||
|
|
||||||
# enable pprof on port 9999 to monitor performances.
|
# enable pprof on port 9999 to monitor performances.
|
||||||
pprof: no
|
pprof: no
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue