From a643a3abc67941dc5a1264a46284f90394cf4498 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Fri, 9 Jun 2023 13:42:00 +0800 Subject: [PATCH] temp commit --- gala-ops/server/httphandler/metricdata.go | 29 ++++------------------- gala-ops/server/main.go | 10 ++++---- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index 1def2d68..d3ef7033 100644 --- a/gala-ops/server/httphandler/metricdata.go +++ b/gala-ops/server/httphandler/metricdata.go @@ -1,7 +1,7 @@ package httphandler import ( - "fmt" + "net/http" "time" "gitee.com/openeuler/PilotGo-plugins/sdk/logger" @@ -37,24 +37,8 @@ func PrometheusAPI(URL string) (prome.API, error) { return promeapi, nil } -func PrometheusMetrics(ctx *gin.Context, promeclient prome.API) { - // bs, err := utils.Request("GET", client.Server+"plugins") - // if err != nil { - // logger.Error("faild to get plugin list: ", err) - // } - // plugins := &[]*Plugin{} - // err = json.Unmarshal(bs, plugins) - // if err != nil { - // logger.Error("unmarshal request plugin info error:%s", err.Error()) - // } - // var Prometheus_addr string - // for _, p := range *plugins { - // if p.Name == "gala-ops" { - // Prometheus_addr = p.Url - // } - // } - - // 查询所有metrics列表 +func TargetsList(ctx *gin.Context, promeclient prome.API) { + // 查询prometheus监控对象列表 result, warnings, err := promeclient.Query(ctx, "up", time.Now()) if err != nil { @@ -67,10 +51,5 @@ func PrometheusMetrics(ctx *gin.Context, promeclient prome.API) { return } - fmt.Println("Metrics:") - fmt.Println(result) - // for _, metric := range result { - // fmt.Println(metric) - // } - + ctx.JSON(http.StatusOK, result) } diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index 7b5096d2..75632c43 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -91,10 +91,12 @@ func InitRouter(router *gin.Engine) { api.PUT("/install_gopher", httphandler.InstallGopher) api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) + } - // 从prometheus中获取监控数据 - api.GET("/metrics", func(ctx *gin.Context) { - httphandler.PrometheusMetrics(ctx, PromeClient) + metrics := router.Group("plugin/gala-ops/api/metrics") + { + metrics.GET("/targets_list", func(ctx *gin.Context) { + httphandler.TargetsList(ctx, PromeClient) }) } } @@ -117,7 +119,7 @@ func getpromeplugininfo(pilotgoserver string) (map[string]interface{}, error) { } var PromePlugin map[string]interface{} for _, p := range data["data"].([]interface{}) { - if p.(map[string]interface{})["name"] == "prometheus" { + if p.(map[string]interface{})["name"] == "Prometheus" { PromePlugin = p.(map[string]interface{}) } } -- Gitee