From 74baeadf6245d5860837d6cfdc2168bf64902cec Mon Sep 17 00:00:00 2001 From: zhanghan Date: Mon, 4 Sep 2023 14:29:27 +0800 Subject: [PATCH] add pilotgo server config --- server/config.yml.templete | 17 ++++++++++------- server/config/config.go | 25 ++++++++++++++++--------- server/main.go | 8 ++++---- server/plugin/plugin_manager.go | 8 ++++---- server/router/router.go | 16 ++++++++-------- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/server/config.yml.templete b/server/config.yml.templete index 67c97cb..a5fe693 100644 --- a/server/config.yml.templete +++ b/server/config.yml.templete @@ -1,12 +1,15 @@ -prometheus: - url: "http://localhost:8090/plugin/Prometheus" - plugin_type: "micro-app" - reverseDest: "http://localhost:9090" -http: - addr: "0.0.0.0:8090" +plugin_prometheus: + url: "http://localhost:8090/plugin/prometheus" + plugin_type: "iframe" # iframe micro-app +prometheus_server: + addr: "localhost:9090" +http_server: + addr: "localhost:8090" +pilotgo_server: + addr: "0.0.0.0:8888" log: level: debug - driver: file # 可选stdout和file。stdout:输出到终端控制台;file:输出到path下的指定文件。 + driver: file #可选stdout和file。stdout:输出到终端控制台;file:输出到path下的指定文件。 path: ./log/plugin_prometheus.log max_file: 1 max_size: 10485760 diff --git a/server/config/config.go b/server/config/config.go index 97fac6e..f579061 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -9,12 +9,17 @@ import ( "gopkg.in/yaml.v2" ) -type Prometheus struct { - URL string `yaml:"url"` - PluginType string `yaml:"plugin_type"` - ReverseDest string `yaml:"reverseDest"` +type PluginPrometheus struct { + URL string `yaml:"url"` + PluginType string `yaml:"plugin_type"` } -type HttpConf struct { +type PrometheusServer struct { + Addr string `yaml:"addr"` +} +type HttpServer struct { + Addr string `yaml:"addr"` +} +type PilotGoServer struct { Addr string `yaml:"addr"` } @@ -27,10 +32,12 @@ type MysqlDBInfo struct { } type ServerConfig struct { - Prometheus *Prometheus `yaml:"prometheus"` - Http *HttpConf `yaml:"http"` - Logopts *logger.LogOpts `yaml:"log"` - Mysql *MysqlDBInfo `yaml:"mysql"` + PluginPrometheus *PluginPrometheus `yaml:"plugin_prometheus"` + PrometheusServer *PrometheusServer `yaml:"prometheus_server"` + HttpServer *HttpServer `yaml:"http_server"` + PilotGoServer *PilotGoServer `yaml:"pilotgo_server"` + Logopts *logger.LogOpts `yaml:"log"` + Mysql *MysqlDBInfo `yaml:"mysql"` } const config_file = "./config.yml" diff --git a/server/main.go b/server/main.go index 7d5db8f..46cbc8a 100644 --- a/server/main.go +++ b/server/main.go @@ -24,7 +24,7 @@ func main() { os.Exit(-1) } - if err := service.InitPrometheus(config.Config().Http.Addr); err != nil { + if err := service.InitPrometheus(config.Config().HttpServer.Addr); err != nil { logger.Error("check prometheus error: %s", err) os.Exit(-1) } @@ -36,12 +36,12 @@ func main() { server := router.InitRouter() - global.GlobalClient = client.DefaultClient(plugin.Init(config.Config().Prometheus)) + global.GlobalClient = client.DefaultClient(plugin.Init(config.Config().PluginPrometheus, config.Config().PrometheusServer)) router.RegisterAPIs(server) router.StaticRouter(server) - global.GlobalClient.Server = config.Config().Http.Addr + global.GlobalClient.Server = config.Config().HttpServer.Addr - if err := server.Run(config.Config().Http.Addr); err != nil { + if err := server.Run(config.Config().HttpServer.Addr); err != nil { logger.Fatal("failed to run server") } } diff --git a/server/plugin/plugin_manager.go b/server/plugin/plugin_manager.go index 4ccd680..3ce1fa8 100644 --- a/server/plugin/plugin_manager.go +++ b/server/plugin/plugin_manager.go @@ -5,16 +5,16 @@ import ( "openeuler.org/PilotGo/prometheus-plugin/config" ) -func Init(conf *config.Prometheus) *client.PluginInfo { +func Init(plugin *config.PluginPrometheus, prometheus *config.PrometheusServer) *client.PluginInfo { PluginInfo := client.PluginInfo{ Name: "prometheus", Version: "0.0.1", Description: "Prometheus开源系统监视和警报工具包", Author: "zhanghan", Email: "zhanghan@kylinos.cn", - Url: conf.URL, - PluginType: conf.PluginType, - ReverseDest: conf.ReverseDest, + Url: plugin.URL, + PluginType: plugin.PluginType, + ReverseDest: "http://" + prometheus.Addr, } return &PluginInfo diff --git a/server/router/router.go b/server/router/router.go index 8c56d21..bbe6d03 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -23,12 +23,6 @@ func RegisterAPIs(router *gin.Engine) { logger.Debug("router register") global.GlobalClient.RegisterHandlers(router) - // prometheus配置文件http方式获取监控target - DBTarget := router.Group("/plugin/" + global.GlobalClient.PluginInfo.Name) - { - DBTarget.GET("target", httphandler.DBTargets) - } - // prometheus api代理 prometheus := router.Group("/plugin/" + global.GlobalClient.PluginInfo.Name + "/api/v1") { @@ -51,6 +45,12 @@ func RegisterAPIs(router *gin.Engine) { } + // prometheus配置文件http方式获取监控target + DBTarget := router.Group("/plugin/" + global.GlobalClient.PluginInfo.Name) + { + DBTarget.GET("target", httphandler.DBTargets) + } + //prometheus target crud targetManager := router.Group("/plugin/" + global.GlobalClient.PluginInfo.Name) { @@ -65,8 +65,8 @@ func StaticRouter(router *gin.Engine) { // 解决页面刷新404的问题 router.NoRoute(func(c *gin.Context) { - logger.Info("process noroute: %s", c.Request.URL.RawPath) - if !strings.HasPrefix(c.Request.RequestURI, "/api/") && !strings.HasPrefix(c.Request.RequestURI, "/plugin/prometheus") { + logger.Error("process noroute: %s", c.Request.URL.RawPath) + if !strings.HasPrefix(c.Request.RequestURI, "/plugin/prometheus") { c.File("./web/dist/index.html") return } -- Gitee