Skip to content

Commit

Permalink
Merge pull request #13 from Decard6/feature/separate-metrics-server
Browse files Browse the repository at this point in the history
gin-metrics support separate metric port
  • Loading branch information
penglongli authored Sep 23, 2021
2 parents a1791f9 + 22bd5f9 commit 03b7643
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ginmetrics/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ func (m *Monitor) Use(r gin.IRoutes) {
})
}

// UseWithoutExposingEndpoint is used to add monitor interceptor to gin router
// It can be called multiple times to intercept from multiple gin.IRoutes
// http path is not set, to do that use Expose function
func (m *Monitor) UseWithoutExposingEndpoint(r gin.IRoutes) {
m.initGinMetrics()
r.Use(m.monitorInterceptor)
}

// Expose adds metric path to a given router.
// The router can be different than the one passed to UseWithoutExposingEndpoint.
// This alows to expose metrics on different port.
func (m *Monitor) Expose(r gin.IRoutes) {
r.GET(m.metricPath, func(ctx *gin.Context) {
promhttp.Handler().ServeHTTP(ctx.Writer, ctx.Request)
})
}

// initGinMetrics used to init gin metrics
func (m *Monitor) initGinMetrics() {
bloomFilter = bloom.NewBloomFilter()
Expand Down

0 comments on commit 03b7643

Please sign in to comment.