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已经加载了新的配置文件。

相关推荐
yunson_Liu1 天前
记一次logrotate.service处理过程
prometheus
TechWJ2 天前
Ansible 跨千台机器批量部署,Node Exporter 监控实现 Prometheus 统一采集
ansible·prometheus
却话巴山夜雨时i2 天前
互联网大厂Java面试:从Spring Boot到Kafka的业务场景深度剖析
spring boot·redis·spring cloud·微服务·kafka·prometheus·java面试
洒满阳光的午后3 天前
我做了一个“能理解业务语义”的可观测性 MCP Server:统一接入 Prometheus、OpenObserve 和 SkyWalking
人工智能·ai·prometheus·skywalking·openobserve·mcp
梵得儿SHI3 天前
SpringCloud 实战落地:可观测性建设(SkyWalking + Prometheus + Grafana)从 0 到 1 生产级部署
grafana·prometheus·springcloud·skywalking·微服务可观测性·线上问题排查
却话巴山夜雨时i4 天前
互联网大厂Java面试场景:Spring Boot、微服务与Redis实战解析
spring boot·redis·微服务·kafka·prometheus·java面试·电商场景
是店小二呀4 天前
Prometheus自定义指标实现方案:技术选型与实战评估
prometheus
南梦浅5 天前
【无标题】
prometheus
2301_旺仔5 天前
【prometheus】监控linux/windows
linux·windows·prometheus
BullSmall6 天前
Prometheus 如何配置监控 SSL 证书即将过期
网络协议·ssl·prometheus