From c201cfa67b689863fafb0d6039f868477275ff73 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Mon, 12 Jun 2023 13:34:45 +0800 Subject: [PATCH] add opsclient in gala-ops plugin --- gala-ops/server/httphandler/component.go | 10 +++++++++ gala-ops/server/httphandler/metricdata.go | 14 +----------- gala-ops/server/main.go | 26 ++++++++++++----------- 3 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 gala-ops/server/httphandler/component.go diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/httphandler/component.go new file mode 100644 index 00000000..901f1f80 --- /dev/null +++ b/gala-ops/server/httphandler/component.go @@ -0,0 +1,10 @@ +package httphandler + +import "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" + +type Opsclient struct { + Sdkmethod *client.Client + PromePlugin map[string]interface{} +} + +var Galaops *Opsclient diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index f5d72db2..ec4c7168 100644 --- a/gala-ops/server/httphandler/metricdata.go +++ b/gala-ops/server/httphandler/metricdata.go @@ -9,21 +9,9 @@ import ( "github.com/gin-gonic/gin" ) -type Plugin struct { - UUID string `json:"uuid"` - Name string `json:"name"` - Version string `json:"version"` - Description string `json:"description"` - Author string `json:"author"` - Email string `json:"email"` - Url string `json:"url"` - Enabled int `json:"enabled"` - Status string `json:"status"` -} - func TargetsList(ctx *gin.Context) { // 查询prometheus监控对象列表 - bs, err := utils.Request("GET", "http://192.168.75.100:8090/plugin/Prometheu/api/v1/query?query=up") + bs, err := utils.Request("GET", Galaops.PromePlugin["url"].(string)+"/api/v1/query?query=up") if err != nil { logger.Error("faild to get prometheus targets: ", err) } diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index 92108d1f..9edd5c5d 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -39,26 +39,28 @@ func main() { router := gin.Default() - GlobalClient := client.DefaultClient(PluginInfo) + PluginClient := client.DefaultClient(PluginInfo) // 临时给server赋值 - GlobalClient.Server = "http://192.168.75.100:8888" - GlobalClient.RegisterHandlers(router) - InitRouter(router) - + PluginClient.Server = "http://192.168.75.100:8888" // 临时自定义获取prometheus地址方式 - // promeplugin, err := getpromeplugininfo(GlobalClient.Server) - // if err != nil { - // logger.Error(err.Error()) - // os.Exit(1) - // } - // var PromeURL string = promeplugin["Url"].(string) - + promeplugin, err := getpromeplugininfo(PluginClient.Server) + if err != nil { + logger.Error(err.Error()) + os.Exit(1) + } // PromePlugin, err := client.GetClient().GetPluginInfo("prometheus") // if err != nil { // logger.Error("failed to get plugin info from pilotgoserver: ", err) // os.Exit(1) // } + httphandler.Galaops = &httphandler.Opsclient{ + Sdkmethod: PluginClient, + PromePlugin: promeplugin, + } + + httphandler.Galaops.Sdkmethod.RegisterHandlers(router) + InitRouter(router) if err := router.Run(config.Config().Http.Addr); err != nil { logger.Fatal("failed to run server") } -- Gitee