mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 18:45:58 +08:00
Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release
# Conflicts: # internal/rpc/msg/rpcChat.go # pkg/common/prometheus/gather.go
This commit is contained in:
@@ -2,6 +2,7 @@ package prometheus
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -26,6 +27,28 @@ func PrometheusHandler() gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type responseBodyWriter struct {
|
||||
gin.ResponseWriter
|
||||
body *bytes.Buffer
|
||||
}
|
||||
|
||||
func (r responseBodyWriter) Write(b []byte) (int, error) {
|
||||
r.body.Write(b)
|
||||
return r.ResponseWriter.Write(b)
|
||||
}
|
||||
|
||||
func PromeTheusMiddleware(c *gin.Context) {
|
||||
PromeInc(ApiRequestCounter)
|
||||
w := &responseBodyWriter{body: &bytes.Buffer{}, ResponseWriter: c.Writer}
|
||||
c.Writer = w
|
||||
c.Next()
|
||||
if c.Writer.Status() == http.StatusOK {
|
||||
PromeInc(ApiRequestSuccessCounter)
|
||||
} else {
|
||||
PromeInc(ApiRequestFailedCounter)
|
||||
}
|
||||
}
|
||||
|
||||
func PromeInc(counter prometheus.Counter) {
|
||||
if config.Config.Prometheus.Enable {
|
||||
if counter != nil {
|
||||
|
||||
Reference in New Issue
Block a user