From 59b1d531e34a610b84e943fc189e6e4879219e79 Mon Sep 17 00:00:00 2001 From: zhanghan Date: Fri, 20 Dec 2024 09:54:17 +0800 Subject: [PATCH] fix bind static file 404 --- server/config/config.go | 9 +++++++++ server/main.go | 2 +- server/plugin/plugin_manager.go | 4 ++-- server/router/router.go | 18 +++++++++--------- server/scripts/init_prometheus_yml.sh | 2 +- server/scripts/prometheus.yml | 2 +- server/service/extentions.go | 26 +++++++++++++++++++------- 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 33f1133..f4c8e6d 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 a6b4163..46a7255 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 6aee826..4c7708c 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 1af2c74..f018926 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 769c503..ef330a7 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) } -- Gitee