Fix:fix target_up nodata judge for prometheus scrape (#986)

This commit is contained in:
xtan 2022-06-17 22:44:25 +08:00 committed by GitHub
parent 7d326ef306
commit 90db12b513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -22,6 +22,14 @@ import (
"github.com/didi/nightingale/v5/src/server/writer" "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 { type promqlForm struct {
PromQL string `json:"promql"` 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 { if len(ident) > 0 {
// register host // register host
ids[ident] = now ids[ident] = now