prometheus metric_relabel_configs 详解加示例

metric_relabel_configs

对拉取的指标样本数据进行标签处理;和relabel_config有相同的配置和动作;
无法应用于自动生成的时间序列指标,如up

一个用处是屏蔽太昂贵的时序数据;

详细解释参看: prometheus relabel_config 详解加示例

以prometheus的指标prometheus_engine_queries_concurrent_max为例

查询指标

curl 'http://localhost:9090/api/v1/query?' --data-urlencod 'query=prometheus_engine_queries_concurrent_max'
------
{
	"status": "success",
	"data": {
		"resultType": "vector",
		"result": [{
			"metric": {
				"Label": "value1",
				"__name__": "prometheus_engine_queries_concurrent_max",
				"instance": "localhost:9090",
				"job": "prometheus",
				"userLabel1": "value1",
				"userLabel2": "value2"
			},
			"value": [1587829220.743, "20"]
		}]
	}
}
======

删除指标的标签

global:
  scrape_interval:     15s
  evaluation_interval: 15s
alerting:
  alertmanagers:
  - static_configs:
    - targets:
rule_files:
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
        labels:
          userLabel1: value1
          userLabel2: value2
    metric_relabel_configs:
      - regex: userLabel1
        action: labeldrop

重载配置后查询

curl 'http://localhost:9090/api/v1/query?' --data-urlencod 'query=prometheus_engine_queries_concurrent_max'
------
{
	"status": "success",
	"data": {
		"resultType": "vector",
		"result": [{
			"metric": {
				"__name__": "prometheus_engine_queries_concurrent_max",
				"instance": "localhost:9090",
				"job": "prometheus",
				"userLabel2": "value2" //删除了userLabel1标签
			},
			"value": [1587829524.788, "20"]
		}]
	}
}
======

你可能感兴趣的:(prometheus监控系统,prometheus,添加标签,删除标签,替换标签)