From b8297143e2fedfeed4e4d331e0c2bed5f11d114f Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Tue, 13 Jun 2023 16:27:33 +0800 Subject: [PATCH] add httphandler.labelslist in galaops plugin --- gala-ops/server/httphandler/metricdata.go | 11 +++++++++++ gala-ops/server/router/router.go | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index 02435dee..e292c758 100644 --- a/gala-ops/server/httphandler/metricdata.go +++ b/gala-ops/server/httphandler/metricdata.go @@ -8,6 +8,17 @@ import ( "github.com/gin-gonic/gin" ) +// prometheus plugin add /api/v1/labels handler +func LabelsList(ctx *gin.Context) { + promurl := Galaops.PromePlugin["url"].(string) + + data, err := Galaops.QueryMetric(promurl, "labels", "") + if err != nil { + logger.Error("faild to querymetric from prometheus: ", err) + } + ctx.JSON(http.StatusOK, data) +} + func TargetsList(ctx *gin.Context) { // 查询prometheus监控对象列表 promurl := Galaops.PromePlugin["url"].(string) diff --git a/gala-ops/server/router/router.go b/gala-ops/server/router/router.go index d3429737..3a5f06b5 100644 --- a/gala-ops/server/router/router.go +++ b/gala-ops/server/router/router.go @@ -19,8 +19,8 @@ func InitRouter(router *gin.Engine) { metrics := router.Group("plugin/gala-ops/api/metrics") { - // url?job=prometheusHOST + metrics.GET("/labels_list", httphandler.LabelsList) metrics.GET("/targets_list", httphandler.TargetsList) - metrics.GET("/cpu_usage_rate", httphandler.CPUusagerate) + metrics.GET("/cpu_usage_rate", httphandler.CPUusagerate) // url?job=gala-gopher host ip } } -- Gitee