@@ -3,6 +3,14 @@ gin-gonic/gin metrics exporter for Prometheus.
33
44[ 中文] ( README_zh.md )
55
6+ - [ Introduction] ( #Introduction )
7+ - [ Grafana] ( #Grafana )
8+ - [ Installation] ( #Installation )
9+ - [ Usage] ( #Usage )
10+ - [ Custom Metric] ( #Custom-Metric )
11+ - [ Metric with separate port] ( #Metric-with-separate-port )
12+ - [ Contributing] ( #Contributing )
13+
614## Introduction
715
816` gin-metrics ` defines some metrics for gin http-server. There have easy way to use it.
@@ -129,6 +137,35 @@ With `Counter` type metric, you can use `Inc` and `Add` function, don't use `Set
129137
130138For ` Histogram ` and ` Summary ` type metric, should use ` Observe ` function.
131139
140+ ## Metric with separate port
141+
142+ For some users, they don't want to merge the port of the metric with the port of the application.
143+
144+ So we provide a way to separate the metric port. Here is the example.
145+
146+ ``` go
147+ func main () {
148+ appRouter := gin.Default ()
149+ metricRouter := gin.Default ()
150+
151+ m := ginmetrics.GetMonitor ()
152+ // use metric middleware without expose metric path
153+ m.UseWithoutExposingEndpoint (appRouter)
154+ // set metric path expose to metric router
155+ m.Expose (metricRouter)
156+
157+ appRouter.GET (" /product/:id" , func (ctx *gin.Context ) {
158+ ctx.JSON (200 , map [string ]string {
159+ " productId" : ctx.Param (" id" ),
160+ })
161+ })
162+ go func () {
163+ _ = metricRouter.Run (" :8081" )
164+ }()
165+ _ = appRouter.Run (" :8080" )
166+ }
167+ ```
168+
132169## Contributing
133170
134171If someone has a problem or suggestions, you can [ new issues] ( https://github.com/penglongli/gin-metrics/issues/new )
0 commit comments