From 9b3a9f29d930831066b1b9e91510abc2480d809f Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Tue, 9 Aug 2022 20:01:54 +0800 Subject: [PATCH] extract promql to webapi.conf --- docker/n9eetc/webapi.conf | 7 ++++++- etc/webapi.conf | 7 ++++++- src/webapi/config/config.go | 1 + src/webapi/router/router_target.go | 11 ++++------- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/docker/n9eetc/webapi.conf b/docker/n9eetc/webapi.conf index d599485a..f03a4ac4 100644 --- a/docker/n9eetc/webapi.conf +++ b/docker/n9eetc/webapi.conf @@ -174,4 +174,9 @@ Address = "http://ibex:10090" BasicAuthUser = "ibex" BasicAuthPass = "ibex" # unit: ms -Timeout = 3000 \ No newline at end of file +Timeout = 3000 + +[TargetMetrics] +TargetUp = "max(max_over_time(target_up{ident=~"(%s)"}[%dm])) by (ident)" +LoadPerCore = "max(max_over_time(system_load_norm_1{ident=~"(%s)"}[%dm])) by (ident)" +MemUtil = "100-max(max_over_time(mem_available_percent{ident=~"(%s)"}[%dm])) by (ident)" \ No newline at end of file diff --git a/etc/webapi.conf b/etc/webapi.conf index 5e9c44cf..7f3ffe08 100644 --- a/etc/webapi.conf +++ b/etc/webapi.conf @@ -201,4 +201,9 @@ Address = "http://127.0.0.1:10090" BasicAuthUser = "ibex" BasicAuthPass = "ibex" # unit: ms -Timeout = 3000 \ No newline at end of file +Timeout = 3000 + +[TargetMetrics] +TargetUp = "max(max_over_time(target_up{ident=~"(%s)"}[%dm])) by (ident)" +LoadPerCore = "max(max_over_time(system_load_norm_1{ident=~"(%s)"}[%dm])) by (ident)" +MemUtil = "100-max(max_over_time(mem_available_percent{ident=~"(%s)"}[%dm])) by (ident)" \ No newline at end of file diff --git a/src/webapi/config/config.go b/src/webapi/config/config.go index c268888d..7ff8d7ad 100644 --- a/src/webapi/config/config.go +++ b/src/webapi/config/config.go @@ -99,6 +99,7 @@ type Config struct { Clusters []ClusterOptions Ibex Ibex OIDC oidcc.Config + TargetMetrics map[string]string } type ClusterOptions struct { diff --git a/src/webapi/router/router_target.go b/src/webapi/router/router_target.go index 18939a04..dac8daf1 100644 --- a/src/webapi/router/router_target.go +++ b/src/webapi/router/router_target.go @@ -13,13 +13,10 @@ import ( "github.com/didi/nightingale/v5/src/models" "github.com/didi/nightingale/v5/src/server/common/conv" + "github.com/didi/nightingale/v5/src/webapi/config" "github.com/didi/nightingale/v5/src/webapi/prom" ) -var promqlLoadPerCore = `max(max_over_time(system_load_norm_1{ident=~"(%s)"}[%dm])) by (ident)` -var promqlMemUtil = `100-max(max_over_time(mem_available_percent{ident=~"(%s)"}[%dm])) by (ident)` -var promqlTargetUp = `max(max_over_time(target_up{ident=~"(%s)"}[%dm])) by (ident)` - func targetGets(c *gin.Context) { bgid := ginx.QueryInt64(c, "bgid", -1) query := ginx.QueryStr(c, "query", "") @@ -62,7 +59,7 @@ func targetGets(c *gin.Context) { } // load per core - promql := fmt.Sprintf(promqlLoadPerCore, strings.Join(targetArr, "|"), mins) + promql := fmt.Sprintf(config.C.TargetMetrics["LoadPerCore"], strings.Join(targetArr, "|"), mins) values, err := instantQuery(c, cc, promql, now) ginx.Dangerous(err) @@ -75,7 +72,7 @@ func targetGets(c *gin.Context) { } // mem util - promql = fmt.Sprintf(promqlMemUtil, strings.Join(targetArr, "|"), mins) + promql = fmt.Sprintf(config.C.TargetMetrics["MemUtil"], strings.Join(targetArr, "|"), mins) values, err = instantQuery(c, cc, promql, now) ginx.Dangerous(err) @@ -88,7 +85,7 @@ func targetGets(c *gin.Context) { } // target up - promql = fmt.Sprintf(promqlTargetUp, strings.Join(targetArr, "|"), mins) + promql = fmt.Sprintf(config.C.TargetMetrics["TargetUp"], strings.Join(targetArr, "|"), mins) values, err = instantQuery(c, cc, promql, now) ginx.Dangerous(err)