From c1d66faa109199cb7695ddc0cb37f2d8668e213a Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 4 Jul 2024 16:36:20 +0800 Subject: [PATCH] api prommetrics --- internal/api/router.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/api/router.go b/internal/api/router.go index 1c70c6bc5..0a42d82bd 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -21,17 +21,15 @@ import ( func prommetricsGin() gin.HandlerFunc { return func(c *gin.Context) { - //start := time.Now() c.Next() path := c.FullPath() - prommetrics.HttpCall(path, c.Request.Method, c.Writer.Status()) - //prommetrics.HttpCall(path, c.Request.Method, c.Writer.Status(), time.Since(start)) - if c.Request.Method == http.MethodPost { - if resp := apiresp.GetGinApiResponse(c); resp == nil { - prommetrics.APICall(path, -1) - } else { - prommetrics.APICall(path, resp.ErrCode) - } + if c.Writer.Status() == http.StatusNotFound { + prommetrics.HttpCall("<404>", c.Request.Method, c.Writer.Status()) + } else { + prommetrics.HttpCall(path, c.Request.Method, c.Writer.Status()) + } + if resp := apiresp.GetGinApiResponse(c); resp != nil { + prommetrics.APICall(path, c.Request.Method, resp.ErrCode) } } }