Browse Source
Merge pull request #89 from lsytj0413/metrics-use-http
fix(server): use http as prom server
pull/99/head
yedf2
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
9 additions and
15 deletions
-
common/types.go
-
dtmsvr/api_http.go
-
dtmsvr/dtmsvr.go
-
dtmsvr/metrics.go
|
|
|
@ -18,9 +18,8 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
DtmHttpPort = 36789 |
|
|
|
DtmGrpcPort = 36790 |
|
|
|
DtmMetricsPort = 8889 |
|
|
|
DtmHttpPort = 36789 |
|
|
|
DtmGrpcPort = 36790 |
|
|
|
) |
|
|
|
|
|
|
|
// MicroService config type for micro service
|
|
|
|
|
|
|
|
@ -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) { |
|
|
|
|
|
|
|
@ -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) |
|
|
|
|
|
|
|
@ -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) |
|
|
|
|