首页 > 其他 > 详细

Prometheus 标签使用示例整合

时间:2019-08-02 16:14:36      阅读:393      评论:0      收藏:0      [点我收藏+]

Prometheus 监控实例


一、Prometheus 根据标签聚合总CPU使用率

1、主机添加标签(可在多个主机内添加相同标签实现聚合):vim prometheus.conf

static_configs:
- targets: [localhost:9090]
  # 添加标签选项
  labels:
  # 标签key:标签value 
  idc: bj

2、检查配置文件

./promtool check config prometheus.yml

3、配置文件重新生效

kill -hup PID

4、监控平台:使用promSQL查询指定标签内主机的所有CPU总和

sum(process_cpu_seconds_total{idc="bj"})

二、Prometheus 重命名标签 根据标签聚合总CPU使用率

1、修改配置文件:vim prometheus.conf

scrape_configs:
  # 作业改为bj
  - job_name: bj
    static_configs:
    - targets: [localhost:9090]
# 添加重命名标签
    relabel_configs:
# 基于正则表达式匹配操作
    - action: replace
  # 指定源标签 
      source_labels: [job]
  # 写入正则,捕获值
      regex: (.*)
  # 替换正则表达式匹配到的分组,分组引用 $1
      replacement: $1
  # 重新标记标签 为 idc
      target_label: idc

2、检查配置文件

./promtool check config prometheus.yml

3、配置文件重新生效

kill -hup PID

4、使用promSQL查询指定标签内主机的所有CPU总和

sum(process_cpu_seconds_total{job="bj"})

三、Prometheus 根据标签过滤目标

1、指定标签下的主机停止数据采集

scrape_configs:
  - job_name: bj
    static_configs:
    - targets: [localhost:9090]
    relabel_configs:
    # 启动drop标签过滤,被指定到的标签停止数据采集
    - action: drop
      # 指定 job 标签
      source_labels: [job]

2、指定标签下的主机保留数据采集

scrape_configs:
  - job_name: bj
    static_configs:
    - targets: [localhost:9090]
    relabel_configs:
    # 启动keep标签过滤,被指定到的标签保留数据采集
    - action: keep
      # 指定 job 标签
      source_labels: [job]

四、Prometheus 删除标签

1、删除标签动作

scrape_configs:
  - job_name: bj
    static_configs:
    - targets: [localhost:9090]
    relabel_configs:
    # 删除指定标签
    - action: labeldrop
      # 指定 job 标签
      regex: job

 

Prometheus 标签使用示例整合

原文:https://www.cnblogs.com/xiangsikai/p/11289066.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!