fix: 性能分析监控prometheus

This commit is contained in:
TsMask
2024-05-18 15:35:54 +08:00
parent 835c2b7420
commit 39067c6381
3 changed files with 36 additions and 18 deletions

View File

@@ -24,7 +24,9 @@ import (
"be.ems/restagent/config"
"be.ems/src"
"be.ems/src/framework/middleware"
"github.com/chenjiandongx/ginprom"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
@@ -193,14 +195,6 @@ func main() {
app := src.AppEngine()
conf := config.GetYamlConfig()
if conf.Pprof.Enabled {
// 启用pprof HTTP服务
go func() {
fmt.Println(http.ListenAndServe(conf.Pprof.Addr, nil))
}()
}
log.InitLogger(conf.Logger.File, conf.Logger.Duration, conf.Logger.Count, "omc:restagent", config.GetLogLevel())
fmt.Printf("OMC restagent version: %s\n", global.Version)
log.Infof("========================= OMC restagent startup =========================")
@@ -251,8 +245,16 @@ func main() {
// AMF上报的UE事件, 无前缀,暂时特殊处理
app.POST(event.UriUEEvent, event.PostUEEventFromAMF)
// 开启监控采集
// monitor.StartMonitor(false, "")
// 性能分析监控
if conf.Pprof.Enabled {
app.Use(ginprom.PromMiddleware(nil))
app.GET("/metrics", ginprom.PromHandler(promhttp.Handler()))
// 启用pprof HTTP服务
go func() {
fmt.Println(http.ListenAndServe(conf.Pprof.Addr, nil))
}()
}
var listenLocalhost bool = false
for _, rest := range conf.Rest {