mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
27 lines
541 B
Go
27 lines
541 B
Go
package prometheus
|
|
|
|
import (
|
|
"Open_IM/pkg/common/config"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
func StartPromeSrv(promethuesPort int) error {
|
|
if config.Config.Prometheus.Enable {
|
|
http.Handle("/metrics", promhttp.Handler())
|
|
err := http.ListenAndServe(":"+strconv.Itoa(promethuesPort), nil)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func PrometheusHandler() gin.HandlerFunc {
|
|
h := promhttp.Handler()
|
|
return func(c *gin.Context) {
|
|
h.ServeHTTP(c.Writer, c.Request)
|
|
}
|
|
}
|