From b511989b43ddf1ceac27d2eb7602ae848c4ebae5 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Fri, 16 Jun 2023 11:35:57 +0800 Subject: [PATCH] add prometheusplugin status check in galaops --- gala-ops/server/httphandler/component.go | 12 ++++++++++-- gala-ops/server/main.go | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/httphandler/component.go index f15c9619..555e3532 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 bb6f2cb0..bedaf77e 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 -- Gitee