diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index 1def2d68bbe69efd7fa6ce8706ab071e3e1a5c99..d3ef7033a6e454f99dc8445a2aff60d4faa0ab68 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 7b5096d29b29761ff3b581b37c8148542bd6b12e..75632c43ce77ed96d28e9acbfa28e21ea856ea9c 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{}) } }