diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/httphandler/component.go index f15c9619c68e2553a9e5d3329915ba33151af88c..555e35321ff31df8f0fd6ce85602296832217aa1 100644 --- a/gala-ops/server/httphandler/component.go +++ b/gala-ops/server/httphandler/component.go @@ -14,7 +14,6 @@ import ( "strings" "time" - "gitee.com/openeuler/PilotGo-plugins/sdk/logger" "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" "gitee.com/openeuler/PilotGo-plugins/sdk/utils/httputils" ) @@ -67,7 +66,7 @@ func (o *Opsclient) QueryMetric(endpoint string, querymethod string, param strin func (o *Opsclient) Getplugininfo(pilotgoserver string, pluginname string) (map[string]interface{}, error) { resp, err := http.Get(pilotgoserver + "/api/v1/plugins") if err != nil { - logger.Error("faild to get plugin list: ", err) + return nil, fmt.Errorf("faild to get plugin list: %s", err.Error()) } defer resp.Body.Close() @@ -135,3 +134,12 @@ func (o *Opsclient) SendJsonMode(jsonmodeURL string) (string, int, error) { } return "the target web server does not exist", -1, err } + +func (o *Opsclient) CheckPrometheusPlugin() (bool, error) { + url := Galaops.PromePlugin["url"].(string) + "aaa" + resp, err := httputils.Get(url, nil) + if resp == nil { + return false, err + } + return true, err +} \ No newline at end of file diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index bb6f2cb0070cda8ded3780b55c84638a990fc91f..bedaf77ea141b5f4f9023d6e3aee57ee6b50fa33 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -49,14 +49,19 @@ func main() { promeplugin, err := httphandler.Galaops.Getplugininfo(PluginClient.Server, "Prometheus") if err != nil { logger.Error(err.Error()) - os.Exit(1) } httphandler.Galaops.PromePlugin = promeplugin - // 向prometheus插件发送可视化插件json模板 + // 检查prometheus插件是否在运行 + promepluginstatus, _ := httphandler.Galaops.CheckPrometheusPlugin() + if !promepluginstatus { + logger.Error("prometheus plugin is not running") + } + + // 向prometheus插件发送可视化插件json模板 TODO: prometheus plugin 注册接收jsonmode的路由 respbody, retcode, err := httphandler.Galaops.SendJsonMode("/abc") if err != nil || retcode != 201 { - logger.Error("failed to sendjsonmode to prometheus plugin: ", respbody, retcode, err) + logger.Error("failed to send jsonmode to prometheus plugin: ", respbody, retcode, err) } // 设置router