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:
skiffer-git
2022-09-15 12:27:55 +08:00
19 changed files with 236 additions and 26 deletions
+23
View File
@@ -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 {