diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/httphandler/component.go new file mode 100644 index 0000000000000000000000000000000000000000..901f1f80063eeab1baa9948182cc17c933e4eb2b --- /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 f5d72db2d70622d7afc5c5fb7894e835c63814d7..ec4c716890c887ecb95c5101f3c30fcc64115cac 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 92108d1f7feff78ef914352a6270a17cbb6f535c..9edd5c5d9ee00ba985ea2d212bcc481f1c43c32b 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") }