prometheus 标签使用

 标签的配置使用

考虑到要明智地使用标签,我们需要给事物重新命名。在一个集中的、复杂的监视环境中,我们有时无法控制正在监视的所有资源以及它们公开的监视数据。重新标记允许在自己的环境中控制、管理和潜在地标准化度量

常见的用例是 :

  • 删除不必要的指标。
  • 从指标中删除敏感或不需要的签。
  • 添加、编辑或修改指标的签值格式。

 

删除metrics

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
    metric_relabel_configs:
      - source_labels: [__name__]
        separator: ','
        regex: '(process_cpu_seconds_total|process_open_fds)'
        action: drop
  - job_name: 'node_exporter'
    static_configs:
    - targets: ['localhost:9100']
    params:
      collect[]:
        - cpu
        - meminfo
        - diskstats
  - job_name: 'docker'
    static_configs:
    - targets: ['192.168.31.151:8080']

备注:如果我们指定了多个源标签,需要用 ; 分开:

regex1;regex2;regex3

 

替换标签

实际上是根据已有的标签,生成一个新标签

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
    metric_relabel_configs:
      - source_labels: [__name__]
        separator: ','
        regex: '(process_cpu_seconds_total|process_open_fds)'
        action: drop
      - source_labels: [version]
        regex: 'go1.*'
        replacement: 'go_unknown'
        target_label: go_version
  - job_name: 'node_exporter'
    static_configs:
    - targets: ['localhost:9100']
    params:
      collect[]:
        - cpu
        - meminfo
        - diskstats
  - job_name: 'docker'
    static_configs:
    - targets: ['192.168.31.151:8080']

 

删除标签

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
    metric_relabel_configs:
      - source_labels: [__name__]
        separator: ','
        regex: '(process_cpu_seconds_total|process_open_fds)'
        action: drop
      - source_labels: [version]
        regex: 'go1.*'
        replacement: 'go_unknown'
        target_label: go_version
      - regex: 'version'
        action: labeldrop
  - job_name: 'node_exporter'
    static_configs:
    - targets: ['localhost:9100']
    params:
      collect[]:
        - cpu
        - meminfo
        - diskstats
  - job_name: 'docker'
    static_configs:
    - targets: ['192.168.31.151:8080']

  

posted @ 2019-03-31 10:05  shhnwangjian  阅读(5535)  评论(0编辑  收藏  举报