From 822e454fdad9bb41a83640d297ad055e1c30af26 Mon Sep 17 00:00:00 2001 From: zhanghan Date: Fri, 1 Sep 2023 16:56:29 +0800 Subject: [PATCH] add base router --- server/config.yml.templete | 2 +- server/plugin/plugin_manager.go | 2 +- server/router/router.go | 6 +++--- server/scripts/init_prometheus_yml.sh | 2 +- server/scripts/prometheus.yml | 4 ++-- web/src/api/prometheus.ts | 6 +++--- web/src/router/index.ts | 2 +- web/vue.config.js | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/server/config.yml.templete b/server/config.yml.templete index cefac62..1f6ceb5 100644 --- a/server/config.yml.templete +++ b/server/config.yml.templete @@ -1,5 +1,5 @@ prometheus: - url: "http://localhost:8090/plugin/Prometheus" + url: "http://localhost:8090/plugin/prometheus" plugin_type: "micro-app" reverseDest: "http://localhost:9090" http: diff --git a/server/plugin/plugin_manager.go b/server/plugin/plugin_manager.go index abb8420..4ccd680 100644 --- a/server/plugin/plugin_manager.go +++ b/server/plugin/plugin_manager.go @@ -7,7 +7,7 @@ import ( func Init(conf *config.Prometheus) *client.PluginInfo { PluginInfo := client.PluginInfo{ - Name: "Prometheus", + Name: "prometheus", Version: "0.0.1", Description: "Prometheus开源系统监视和警报工具包", Author: "zhanghan", diff --git a/server/router/router.go b/server/router/router.go index 3b16a1b..8c56d21 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -60,13 +60,13 @@ func RegisterAPIs(router *gin.Engine) { } func StaticRouter(router *gin.Engine) { - router.Static("/static", "../web/dist/static") - router.StaticFile("/", "../web/dist/index.html") + router.Static("/plugin/prometheus/static", "../web/dist/static") + router.StaticFile("/plugin/prometheus", "../web/dist/index.html") // 解决页面刷新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") { + if !strings.HasPrefix(c.Request.RequestURI, "/api/") && !strings.HasPrefix(c.Request.RequestURI, "/plugin/prometheus") { c.File("./web/dist/index.html") return } diff --git a/server/scripts/init_prometheus_yml.sh b/server/scripts/init_prometheus_yml.sh index ed9bf3d..a9502de 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/target refresh_interval: 60s EOF echo "初始化" diff --git a/server/scripts/prometheus.yml b/server/scripts/prometheus.yml index 1ea8fc5..fc45fc4 100644 --- a/server/scripts/prometheus.yml +++ b/server/scripts/prometheus.yml @@ -7,5 +7,5 @@ rule_files: scrape_configs: - job_name: node_exporter http_sd_configs: - - url: http://localhost:8090/plugin/Prometheus/target - refresh_interval: 60s \ No newline at end of file + - url: http://localhost:8090/plugin/prometheus/target + refresh_interval: 60s diff --git a/web/src/api/prometheus.ts b/web/src/api/prometheus.ts index fc9d44b..d43f935 100644 --- a/web/src/api/prometheus.ts +++ b/web/src/api/prometheus.ts @@ -2,7 +2,7 @@ import request from './request' // 获取指标列表 export function getPromRules() { return request({ - url: '/plugin/Prometheus/api/v1/targets', + url: '/plugin/prometheus/api/v1/targets', method: 'get', }) } @@ -10,7 +10,7 @@ export function getPromRules() { // 获取prome某一时间点的数据 export function getPromeCurrent(data: object) { return request({ - url: '/plugin/Prometheus/api/v1/query', + url: '/plugin/prometheus/api/v1/query', method: 'get', params: data }) @@ -19,7 +19,7 @@ export function getPromeCurrent(data: object) { // 获取prome某一时间段的数据 export function getPromeRange(data: object) { return request({ - url: '/plugin/Prometheus/api/v1/query_range', + url: '/plugin/prometheus/api/v1/query_range', method: 'get', params: data }) diff --git a/web/src/router/index.ts b/web/src/router/index.ts index c28a34b..7238455 100644 --- a/web/src/router/index.ts +++ b/web/src/router/index.ts @@ -10,7 +10,7 @@ const routes: Array = [ ] const router = createRouter({ - history: createWebHashHistory(), + history: createWebHashHistory('/plugin/prometheus'), routes }) diff --git a/web/vue.config.js b/web/vue.config.js index 361fa43..f6b0fff 100644 --- a/web/vue.config.js +++ b/web/vue.config.js @@ -5,7 +5,7 @@ module.exports = { }, proxy: { '/': { - target: 'http://localhost:8082', + target: 'http://localhost:8090', ws: false, changeOrigin: true, } @@ -15,8 +15,8 @@ module.exports = { }, // 静态资源 - publicPath: "./", - outputDir: "dist",//"../server/resource/dist", + publicPath: "./prometheus", + outputDir: "dist", assetsDir: "static", indexPath: "index.html", filenameHashing: true, -- Gitee