diff --git a/server/config/config.go b/server/config/config.go index 33f1133e25ccab8a6b922def6500b710bbfc15ce..f4c8e6d68fc50f049ef95eb26b41a99d6a3034ba 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -10,6 +10,7 @@ package config import ( "fmt" "os" + "time" "gitee.com/openeuler/PilotGo/sdk/logger" "gopkg.in/yaml.v2" @@ -36,12 +37,20 @@ type MysqlDBInfo struct { DataBase string `yaml:"database"` } +type Etcd struct { + Endpoints []string `yaml:"endpoints" mapstructure:"endpoints"` + ServiveName string `yaml:"service_name" mapstructure:"service_name"` + Version string `yaml:"version" mapstructure:"version"` + DialTimeout time.Duration `yaml:"dialTimeout" mapstructure:"dialTimeout"` +} + type ServerConfig struct { PluginPrometheus *PluginPrometheus `yaml:"plugin_prometheus"` PrometheusServer *PrometheusServer `yaml:"prometheus_server"` HttpServer *HttpServer `yaml:"http_server"` Logopts *logger.LogOpts `yaml:"log"` Mysql *MysqlDBInfo `yaml:"mysql"` + Etcd *Etcd `yaml:"etcd" mapstructure:"etcd"` } const config_file = "./config.yml" diff --git a/server/main.go b/server/main.go index a6b41630f216dd50583c4267c6b05a0a5c25a1b3..46a72555208be6a9604b64b15ea13150467786f5 100644 --- a/server/main.go +++ b/server/main.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-prometheus licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-prometheus licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: zhanghan2021 * Date: Wed Jul 26 16:42:38 2023 +0800 diff --git a/server/plugin/plugin_manager.go b/server/plugin/plugin_manager.go index 6aee826ea9775fd7df5aee2a4515a54f7d599d87..4c7708c3112aae5078ac0073feea2c9909dc8734 100644 --- a/server/plugin/plugin_manager.go +++ b/server/plugin/plugin_manager.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-prometheus licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-prometheus licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: zhanghan2021 * Date: Wed Jul 26 16:42:38 2023 +0800 @@ -22,7 +22,7 @@ func Init(plugin *config.PluginPrometheus, prometheus *config.PrometheusServer) Author: "zhanghan", Email: "zhanghan@kylinos.cn", Url: plugin.URL, - PluginType: "iframe", + PluginType: "micro-app", ReverseDest: "http://" + prometheus.Addr, } diff --git a/server/router/router.go b/server/router/router.go index 1af2c7407fd94f7504d194039f8989b547537638..f018926a521e881917577a1b0491dca1058c2b53 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -36,7 +36,8 @@ func RegisterAPIs(router *gin.Engine) { sdk.UnPluginListenEventHandler() // prometheus api代理 - prometheus := router.Group("/plugin/" + plugin.Client.PluginInfo.Name + "/api/v1") + api := router.Group("/plugin/" + plugin.Client.PluginInfo.Name + "/api") + prometheus := api.Group("") { prometheus.GET("/query", func(c *gin.Context) { c.Set("query", plugin.Client.PluginInfo.ReverseDest) @@ -58,20 +59,20 @@ func RegisterAPIs(router *gin.Engine) { } // prometheus配置文件http方式获取监控target - DBTarget := router.Group("/plugin/" + plugin.Client.PluginInfo.Name) + DBTarget := api.Group("") { DBTarget.GET("target", httphandler.DBTargets) } //prometheus target crud - targetManager := router.Group("/plugin/" + plugin.Client.PluginInfo.Name) + targetManager := api.Group("") { targetManager.POST("run", httphandler.RunCommand) targetManager.GET("monitorlist", httphandler.MonitorTargets) } //prometheus alert rule manager - ruleManager := router.Group("/plugin/" + plugin.Client.PluginInfo.Name) + ruleManager := api.Group("") { ruleManager.POST("ruleAdd", httphandler.AddRuleHandler) ruleManager.GET("ruleQuery", httphandler.QueryRules) @@ -81,7 +82,7 @@ func RegisterAPIs(router *gin.Engine) { } //prometheus alert manager - alertManager := router.Group("/plugin/" + plugin.Client.PluginInfo.Name) + alertManager := api.Group("") { alertManager.GET("alertQuery", httphandler.QuerySearchAlerts) alertManager.POST("alertUpdateState", httphandler.UpdateHandleState) @@ -89,14 +90,13 @@ func RegisterAPIs(router *gin.Engine) { } func StaticRouter(router *gin.Engine) { - router.Static("/plugin/prometheus/static", "../web/dist/static") + router.Static("/plugin/prometheus/assets", "../web/dist/assets") router.StaticFile("/plugin/prometheus", "../web/dist/index.html") // 解决页面刷新404的问题 router.NoRoute(func(c *gin.Context) { - logger.Error("process noroute: %s", c.Request.URL.RawPath) - if !strings.HasPrefix(c.Request.RequestURI, "/plugin/prometheus") { - c.File("./web/dist/index.html") + if !strings.HasPrefix(c.Request.RequestURI, "/plugin/prometheus/api") { + c.File("../web/dist/index.html") return } c.AbortWithStatus(http.StatusNotFound) diff --git a/server/scripts/init_prometheus_yml.sh b/server/scripts/init_prometheus_yml.sh index 769c5036f25b6de562619806af1534c5d6e445fc..ef330a7c15fb930024605a91f6aeab70b2df939a 100644 --- a/server/scripts/init_prometheus_yml.sh +++ b/server/scripts/init_prometheus_yml.sh @@ -9,7 +9,7 @@ rule_files: scrape_configs: - job_name: node_exporter http_sd_configs: - - url: http://$1/plugin/prometheus/target + - url: http://$1/plugin/prometheus/api/target refresh_interval: 60s EOF cat>/etc/prometheus/rules.yaml< * Date: Wed Jan 10 16:23:18 2024 +0800 @@ -17,21 +17,33 @@ func AddExtentions() { me1 := &common.MachineExtention{ Type: common.ExtentionMachine, Name: "安装exporter", - URL: "/plugin/prometheus/run?type=" + CommandInstall_Type, + URL: "/plugin/prometheus/api/run?type=" + CommandInstall_Type, Permission: "plugin.prometheus.agent/install", } me2 := &common.MachineExtention{ Type: common.ExtentionMachine, Name: "卸载exporter", - URL: "/plugin/prometheus/run?type=" + CommandRemove_Type, + URL: "/plugin/prometheus/api/run?type=" + CommandRemove_Type, Permission: "plugin.prometheus.agent/uninstall", } - pe := &common.PageExtention{ + pe1 := &common.PageExtention{ Type: common.ExtentionPage, - Name: "plugin-prometheus", - URL: "/plugin/prometheus", + Name: "监控大屏", + URL: "/", Permission: "plugin.prometheus.page/menu", } - ex = append(ex, me1, me2, pe) + pe2 := &common.PageExtention{ + Type: common.ExtentionPage, + Name: "告警配置", + URL: "/rule", + Permission: "plugin.prometheus.page/menu", + } + pe3 := &common.PageExtention{ + Type: common.ExtentionPage, + Name: "告警列表", + URL: "/alert", + Permission: "plugin.prometheus.page/menu", + } + ex = append(ex, me1, me2, pe1, pe2, pe3) plugin.Client.RegisterExtention(ex) }