From e15b65a9877cfadab880f0fdf8e7ec979ae9f498 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Tue, 20 Jun 2023 09:22:16 +0800 Subject: [PATCH] move httphandler/component.go to agentmanager/ --- gala-ops/server/.gitignore | 2 ++ .../{httphandler => agentmanager}/component.go | 2 +- gala-ops/server/database/DBmodel.go | 2 +- gala-ops/server/httphandler/agent.go | 4 +++- gala-ops/server/httphandler/metricdata.go | 15 ++++++++------- gala-ops/server/main.go | 14 +++++++------- 6 files changed, 22 insertions(+), 17 deletions(-) rename gala-ops/server/{httphandler => agentmanager}/component.go (99%) diff --git a/gala-ops/server/.gitignore b/gala-ops/server/.gitignore index 924f0758..439b6a52 100644 --- a/gala-ops/server/.gitignore +++ b/gala-ops/server/.gitignore @@ -4,3 +4,5 @@ config.yml # bin files server *.exe + +.vscode \ No newline at end of file diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/agentmanager/component.go similarity index 99% rename from gala-ops/server/httphandler/component.go rename to gala-ops/server/agentmanager/component.go index e8fe812c..4aab1786 100644 --- a/gala-ops/server/httphandler/component.go +++ b/gala-ops/server/agentmanager/component.go @@ -1,4 +1,4 @@ -package httphandler +package agentmanager import ( "bytes" diff --git a/gala-ops/server/database/DBmodel.go b/gala-ops/server/database/DBmodel.go index 312f7e82..ad588157 100644 --- a/gala-ops/server/database/DBmodel.go +++ b/gala-ops/server/database/DBmodel.go @@ -5,7 +5,7 @@ type AopsDepolyStatus struct { UUID string `gorm:"not null" json:"uuid"` IP string `gorm:"not null" json:"ip"` Port string `gorm:"not null" json:"port"` - Department string `gorm:"not null" json:"department"` + Department string `json:"department"` Statu string `gorm:"not null" json:"state"` Gopher_deploy bool // ture:installed false:uninstalled Gopher_running bool // true:running false:not running diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index 9fa0ec4f..7a9ca4e6 100644 --- a/gala-ops/server/httphandler/agent.go +++ b/gala-ops/server/httphandler/agent.go @@ -8,7 +8,9 @@ import ( "gitee.com/openeuler/PilotGo-plugins/sdk/common" "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/gala-ops-plugin/agentmanager" ) + // TODO: 接收到pilotgo server部署aops组件请求后直接响应部署脚本 func InstallGopher(ctx *gin.Context) { param := &common.Batch{} @@ -27,7 +29,7 @@ func InstallGopher(ctx *gin.Context) { }) } - cmdResults, err := Galaops.Sdkmethod.RunScript(param, string(script)) + cmdResults, err := agentmanager.Galaops.Sdkmethod.RunScript(param, string(script)) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ "code": -1, diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index e292c758..6756e26f 100644 --- a/gala-ops/server/httphandler/metricdata.go +++ b/gala-ops/server/httphandler/metricdata.go @@ -6,13 +6,14 @@ import ( "gitee.com/openeuler/PilotGo-plugins/sdk/logger" "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/gala-ops-plugin/agentmanager" ) // prometheus plugin add /api/v1/labels handler func LabelsList(ctx *gin.Context) { - promurl := Galaops.PromePlugin["url"].(string) + promurl := agentmanager.Galaops.PromePlugin["url"].(string) - data, err := Galaops.QueryMetric(promurl, "labels", "") + data, err := agentmanager.Galaops.QueryMetric(promurl, "labels", "") if err != nil { logger.Error("faild to querymetric from prometheus: ", err) } @@ -21,14 +22,14 @@ func LabelsList(ctx *gin.Context) { func TargetsList(ctx *gin.Context) { // 查询prometheus监控对象列表 - promurl := Galaops.PromePlugin["url"].(string) + promurl := agentmanager.Galaops.PromePlugin["url"].(string) param := map[string]string{ "query": "up", } urlparam := fmt.Sprintf("?query=%v", param["query"]) - data, err := Galaops.QueryMetric(promurl, "query", urlparam) + data, err := agentmanager.Galaops.QueryMetric(promurl, "query", urlparam) if err != nil { logger.Error("faild to querymetric from prometheus: ", err) } @@ -36,8 +37,8 @@ func TargetsList(ctx *gin.Context) { } func CPUusagerate(ctx *gin.Context) { - promurl := Galaops.PromePlugin["url"].(string) - start, end := Galaops.UnixTimeStartandEnd(-5) + promurl := agentmanager.Galaops.PromePlugin["url"].(string) + start, end := agentmanager.Galaops.UnixTimeStartandEnd(-5) job := ctx.Query("job") if job == "" { logger.Error("need job parameter in url: cpuusagerate") @@ -52,7 +53,7 @@ func CPUusagerate(ctx *gin.Context) { } urlparam := fmt.Sprintf("?query=%v&start=%v&end=%v&step=%v", param["query"], param["start"], param["end"], param["step"]) - data, err := Galaops.QueryMetric(promurl, "query_range", urlparam) + data, err := agentmanager.Galaops.QueryMetric(promurl, "query_range", urlparam) if err != nil { logger.Error("faild to querymetric from prometheus: ", err) } diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index bedaf77e..81484f9a 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -7,9 +7,9 @@ import ( "gitee.com/openeuler/PilotGo-plugins/sdk/logger" "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/gala-ops-plugin/agentmanager" "openeuler.org/PilotGo/gala-ops-plugin/config" "openeuler.org/PilotGo/gala-ops-plugin/database" - "openeuler.org/PilotGo/gala-ops-plugin/httphandler" "openeuler.org/PilotGo/gala-ops-plugin/router" ) @@ -40,32 +40,32 @@ func main() { PluginClient := client.DefaultClient(PluginInfo) // 临时给server赋值 PluginClient.Server = "http://192.168.75.100:8888" - httphandler.Galaops = &httphandler.Opsclient{ + agentmanager.Galaops = &agentmanager.Opsclient{ Sdkmethod: PluginClient, PromePlugin: nil, } // 临时自定义获取prometheus地址方式 - promeplugin, err := httphandler.Galaops.Getplugininfo(PluginClient.Server, "Prometheus") + promeplugin, err := agentmanager.Galaops.Getplugininfo(PluginClient.Server, "Prometheus") if err != nil { logger.Error(err.Error()) } - httphandler.Galaops.PromePlugin = promeplugin + agentmanager.Galaops.PromePlugin = promeplugin // 检查prometheus插件是否在运行 - promepluginstatus, _ := httphandler.Galaops.CheckPrometheusPlugin() + promepluginstatus, _ := agentmanager.Galaops.CheckPrometheusPlugin() if !promepluginstatus { logger.Error("prometheus plugin is not running") } // 向prometheus插件发送可视化插件json模板 TODO: prometheus plugin 注册接收jsonmode的路由 - respbody, retcode, err := httphandler.Galaops.SendJsonMode("/abc") + respbody, retcode, err := agentmanager.Galaops.SendJsonMode("/abc") if err != nil || retcode != 201 { logger.Error("failed to send jsonmode to prometheus plugin: ", respbody, retcode, err) } // 设置router - httphandler.Galaops.Sdkmethod.RegisterHandlers(engine) + agentmanager.Galaops.Sdkmethod.RegisterHandlers(engine) router.InitRouter(engine) if err := engine.Run(config.Config().Http.Addr); err != nil { logger.Fatal("failed to run server") -- Gitee