diff --git a/internal/api/router.go b/internal/api/router.go index b519c30ff..936d6ab0b 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -2,14 +2,10 @@ package api import ( "fmt" - "github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics" - "net/http" - "strings" - "time" - "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" + "github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics" "github.com/openimsdk/open-im-server/v3/pkg/common/servererrs" "github.com/openimsdk/open-im-server/v3/pkg/rpcclient" "github.com/openimsdk/protocol/constant" @@ -19,14 +15,17 @@ import ( "github.com/openimsdk/tools/mw" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "net/http" + "strings" ) func prommetricsGin() gin.HandlerFunc { return func(c *gin.Context) { - start := time.Now() + //start := time.Now() c.Next() path := c.FullPath() - prommetrics.HttpCall(path, c.Request.Method, c.Writer.Status(), time.Since(start)) + 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, "NO_GIN_RESPONSE_FOUND") diff --git a/pkg/common/prommetrics/api.go b/pkg/common/prommetrics/api.go index ce45290ad..aa5e0a60e 100644 --- a/pkg/common/prommetrics/api.go +++ b/pkg/common/prommetrics/api.go @@ -24,7 +24,8 @@ var ( Name: "http_count", Help: "Total number of HTTP calls", }, - []string{"path", "method", "status", "duration"}, + //[]string{"path", "method", "status", "duration"}, + []string{"path", "method", "status"}, ) ) @@ -36,8 +37,12 @@ func APICall(path string, apiCode int, apiType string) { apiCounter.With(prometheus.Labels{"path": path, "code": strconv.Itoa(apiCode), "type": apiType}).Inc() } -func HttpCall(path string, method string, status int, duration time.Duration) { - httpCounter.With(prometheus.Labels{"path": path, "method": method, "status": strconv.Itoa(status), "duration": durationRange(duration)}).Inc() +//func HttpCall(path string, method string, status int, duration time.Duration) { +// httpCounter.With(prometheus.Labels{"path": path, "method": method, "status": strconv.Itoa(status), "duration": durationRange(duration)}).Inc() +//} + +func HttpCall(path string, method string, status int) { + httpCounter.With(prometheus.Labels{"path": path, "method": method, "status": strconv.Itoa(status)}).Inc() } var (