From 90db12b5132b3067cb8686eb03d678c55423b7b7 Mon Sep 17 00:00:00 2001 From: xtan <38320121+tanxiao1990@users.noreply.github.com> Date: Fri, 17 Jun 2022 22:44:25 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9Afix=20target=5Fup=20nodata=20judge?= =?UTF-8?q?=20for=20prometheus=20scrape=20(#986)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/router/router_prom.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/server/router/router_prom.go b/src/server/router/router_prom.go index 544ac092..c8f3a4e9 100644 --- a/src/server/router/router_prom.go +++ b/src/server/router/router_prom.go @@ -22,6 +22,14 @@ import ( "github.com/didi/nightingale/v5/src/server/writer" ) +var promMetricFilter map[string]bool = map[string]bool{ + "up": true, + "scrape_series_added": true, + "scrape_samples_post_metric_relabeling": true, + "scrape_samples_scraped": true, + "scrape_duration_seconds": true, +} + type promqlForm struct { PromQL string `json:"promql"` } @@ -90,6 +98,14 @@ func remoteWrite(c *gin.Context) { } } + // 当数据是通过prometheus抓取(也许直接remote write到夜莺)的时候,prometheus会自动产生部分系统指标 + // 例如最典型的有up指标,是prometheus为exporter生成的指标,即使exporter挂掉的时候也会送up=0的指标 + // 此类指标当剔除,否则会导致redis数据中时间戳被意外更新,导致由此类指标中携带的ident的相关target_up指标无法变为实际的0值 + // 更多详细信息:https://prometheus.io/docs/concepts/jobs_instances/#automatically-generated-labels-and-time-series + if _, has := promMetricFilter[metric]; has { + ident = "" + } + if len(ident) > 0 { // register host ids[ident] = now