Prometheus 服务发现 添加标签

Prometheus中添加标签可以采用Relabel Config的方式,通过在配置文件中编写relabel_config模块来定义要给哪些目标添加标签,该模块可以实现筛选、替换、修剪、添加等不同的转换操作。 下面是一个添加标签的例子,该例子将添加标签"env: staging"来表示指标来自于测试环境:

复制代码
scrape_configs:
  - job_name: 'example'
    static_configs:
    - targets:
        - example.com
    metric_relabel_configs:
    - source_labels: [__address__]
      regex: example\.com
      replacement: $1
      target_label: instance

#添加新的标签
    - source_labels: []
      regex: ''
      target_label: env
      replacement: 'staging'
  • source_labels: []意味着这个re_label不会有任何来源的标签。
  • regex: ''指定一个空的正则表达式,以允许target_label接收固定字符串"staging"。
  • replacement接收该值并将其放入target_label"env"中的目标实例上。
  • regex: example\.com 将源实例标签 __address__=example.com 的值保存为$1。
  • replacement: $1将更新的目标实例的标签instance 将原始源名称保留在目标标签instance中,以便能够更好地区分不同的目标。

最后,重新加载Prometheus配置或重启Prometheus,以确保Prometheus已经加载了新的配置文件。

相关推荐
oMcLin1 小时前
如何在 CentOS 7.9 上配置并调优 Docker Swarm 集群,确保跨多个节点的高效服务发现与负载均衡?
docker·centos·服务发现
oMcLin17 小时前
如何在 Rocky Linux 8.7 上通过 Prometheus 与 Grafana 结合,提升大规模容器环境的监控与性能分析?
linux·grafana·prometheus
飞翔沫沫情1 天前
Prometheus 监控 ESXi 实战
grafana·prometheus·esxi·vcenter 监控·vsphere 监控
喵叔哟1 天前
19.服务集成与通信
后端·docker·容器·服务发现
莫非王土也非王臣1 天前
Prometheus监控多个网站状态并推送到企业微信群机器人的完整方案
机器人·企业微信·prometheus
goodlook01232 天前
监控平台搭建-日志-alloy篇(八)
grafana·prometheus
三不原则3 天前
实战:Prometheus 监控 GPU 使用率,设置智能告警阈值
prometheus
flying robot4 天前
Prometheus[2.33.3]grafana[12.3.1]监控安装
grafana·prometheus
一只懒鱼a7 天前
Prometheus和Grafana的安装和使用
grafana·prometheus
YanDDDeat7 天前
Prometheus + Grafana 搭建应用监控体系
java·后端·eureka·grafana·prometheus