diff --git a/restagent/config/config.go b/restagent/config/config.go index 1dd3ce9a..c2101870 100644 --- a/restagent/config/config.go +++ b/restagent/config/config.go @@ -20,6 +20,11 @@ type YamlConfig struct { Count int `yaml:"count"` } `yaml:"logger"` + Pprof struct { + Enabled bool `yaml:"enabled"` + Addr string `yaml:"addr"` + } `yaml:"pprof"` + // Rest []struct { // IPv4 string `yaml:"ipv4"` // IPv6 string `yaml:"ipv6"` diff --git a/restagent/etc/restconf.yaml b/restagent/etc/restconf.yaml index abc65bc3..02885305 100644 --- a/restagent/etc/restconf.yaml +++ b/restagent/etc/restconf.yaml @@ -2,11 +2,16 @@ # level: /trace/debug/info/warn/error/fatal, default: debug # duration: rotation time with xx hours, example: 1/12/24 hours # count: rotation count of log, default is 30 rotation +# pprof: false(default)/true to disable/enable pprof logger: file: d:/local.git/be.ems/restagent/log/restagent.log level: trace duration: 24 - count: 2 + count: 2 + +pprof: + enabled: true + addr: :36060 # rest agent listen ipv4/v6 and port, support multiple routines # ip: 0.0.0.0 or ::0, support IPv4/v6 diff --git a/restagent/restagent.go b/restagent/restagent.go index 04aac953..238e4a40 100644 --- a/restagent/restagent.go +++ b/restagent/restagent.go @@ -9,6 +9,8 @@ import ( "strconv" "strings" + _ "net/http/pprof" + "be.ems/features/dbrest" "be.ems/features/event" "be.ems/features/fm" @@ -185,12 +187,20 @@ func HttpListenWebServer(addr string) { } func main() { + // src 配置中心初始加载 src.ConfigurationInit() 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 =========================")