Skip to content

Commit

Permalink
Add metrics server port as function parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
João Bologna committed Sep 5, 2023
1 parent d0ebb10 commit 8321451
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 7 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var startCmd = &cobra.Command{
log.Panic(err)
}
launchPProf()
metrics.StartServer()
launchMetricsServer()
a.Run()
},
}
Expand All @@ -68,6 +68,12 @@ func launchPProf() {
}
}

func launchMetricsServer() {
fmt.Println("Starting Metrics HTTP server")
config.SetDefault("prometheus.port", ":9091")
metrics.StartServer(config.GetString("prometheus.port"))
}

func init() {
startCmd.Flags().StringVarP(&host, "host", "b", "0.0.0.0", "the address of the interface to bind")
startCmd.Flags().IntVarP(&port, "port", "p", 5000, "the port to bind")
Expand Down
7 changes: 1 addition & 6 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package metrics

import (
"fmt"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -126,7 +125,7 @@ var (
// StartServer runs a metrics server inside a goroutine
// that reports default application metrics in prometheus format.
// Any errors that may occur will stop the server add log.Fatal the error.
func StartServer() {
func StartServer(port string) {
prometheus.MustRegister(
APIResponseTime,
APIRequestsFailureCounter,
Expand All @@ -137,10 +136,6 @@ func StartServer() {
ClientRequestsFailureCounter,
ClientRequestsDroppedCounter,
)
port := ":9091"
if envPort, ok := os.LookupEnv("EVENTSGATEWAY_PROMETHEUS_PORT"); ok {
port = fmt.Sprintf(":%s", envPort)
}
go func() {
envEnabled, _ := os.LookupEnv("EVENTSGATEWAY_PROMETHEUS_ENABLED")
if envEnabled != "true" {
Expand Down

0 comments on commit 8321451

Please sign in to comment.