diff --git a/common/types.go b/common/types.go index 414d246..478bea5 100644 --- a/common/types.go +++ b/common/types.go @@ -18,9 +18,8 @@ import ( ) const ( - DtmHttpPort = 36789 - DtmGrpcPort = 36790 - DtmMetricsPort = 8889 + DtmHttpPort = 36789 + DtmGrpcPort = 36790 ) // MicroService config type for micro service diff --git a/dtmsvr/api_http.go b/dtmsvr/api_http.go index 2735bf2..5208102 100644 --- a/dtmsvr/api_http.go +++ b/dtmsvr/api_http.go @@ -11,6 +11,7 @@ import ( "math" "github.com/gin-gonic/gin" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/yedf/dtm/common" "github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli/dtmimp" @@ -26,6 +27,12 @@ func addRoute(engine *gin.Engine) { engine.POST("/api/dtmsvr/registerTccBranch", common.WrapHandler(registerBranch)) // compatible for old sdk engine.GET("/api/dtmsvr/query", common.WrapHandler(query)) engine.GET("/api/dtmsvr/all", common.WrapHandler(all)) + + // add prometheus exporter + h := promhttp.Handler() + engine.GET("/api/metrics", func(c *gin.Context) { + h.ServeHTTP(c.Writer, c.Request) + }) } func newGid(c *gin.Context) (interface{}, error) { diff --git a/dtmsvr/dtmsvr.go b/dtmsvr/dtmsvr.go index 26ed2d2..d5a4c0b 100644 --- a/dtmsvr/dtmsvr.go +++ b/dtmsvr/dtmsvr.go @@ -48,9 +48,6 @@ func StartSvr() { }() go updateBranchAsync() - // prometheus exporter - dtmimp.Logf("prometheus exporter listen at: %d", common.DtmMetricsPort) - prometheusHTTPRun(fmt.Sprintf("%d", common.DtmMetricsPort)) time.Sleep(100 * time.Millisecond) err = dtmdriver.Use(config.MicroService.Driver) dtmimp.FatalIfError(err) diff --git a/dtmsvr/metrics.go b/dtmsvr/metrics.go index 476241b..860818d 100644 --- a/dtmsvr/metrics.go +++ b/dtmsvr/metrics.go @@ -8,13 +8,11 @@ package dtmsvr import ( "context" - "net/http" "strings" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/prometheus/client_golang/prometheus/promhttp" "google.golang.org/grpc" ) @@ -44,13 +42,6 @@ var ( []string{"model", "gid", "branchid", "branchtype", "status"}) ) -func prometheusHTTPRun(port string) { - go func() { - http.Handle("/api/metrics", promhttp.Handler()) - http.ListenAndServe(":"+port, nil) - }() -} - func httpMetrics(app *gin.Engine) *gin.Engine { app.Use(func(c *gin.Context) { api := extractFromPath(c.Request.RequestURI)