go - Gin 将指标发送到 promethesus,其中 URL 在路径中有参数
问题描述
我有一个杜松子酒服务,其中一个端点看起来像这样:
const myPath= "/upload-some-file/:uuid"
在我向普罗米修斯发送数据的中间件中,我有这样的东西:
requestCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "all-http-requests",
Help: "Total number of http requests",
}, []string{"Method", "Endpoint"})
func Telemetry() gin.HandlerFunc {
return func(c *gin.Context) {
// Metrics for requests volume
requestCounter.With(prometheus.Labels{"Method": c.Request.Method, "Endpoint": c.Request.URL.Path}).Inc()
c.Next()
}
}
但是我注意到,prometheus 无法确定参数实际上是嵌入到路径中的,因此它将每个唯一的 uuid 视为新路径。
有没有办法让prometheus意识到它实际上是在使用带有嵌入参数的URL?
解决方案
我发现了这个https://github.com/gin-gonic/gin/issues/748#issuecomment-543683781
所以我可以简单地做得到c.FullPath()
匹配的路线。
推荐阅读
- javascript - 在 HttpStatusCode 中,当我将其更改为 401 时,我再次获得状态 500
- mysql - 如何为审计表编写本机查询
- google-directory-api - 如何使用服务帐户获取域用户的数据?
- redirect - IIS url 重定向太多重定向
- python - 布尔列的趋势
- python - 为什么导入和更新所有嵌套键时的 Python 3.6 字典表示相同的内存位置
- javascript - 在打字稿中声明 for in 循环的键类型
- c# - 在实体中插入记录时,如何重现或修复 DCRM 中的字符串截断异常?
- reactjs - 如何使用`BrowserRouter`或`MemoryRouter`监视`history`?
- wix - 如何在使用 WIX 更新安装程序时处理配置