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

相关推荐
学Linux的语莫2 天前
prometheus、grafana的docker搭建
docker·容器·prometheus
为什么不问问神奇的海螺呢丶2 天前
服务器巡检报告-基于categraf 采集数据-存入Prometheus-写入mysql后生成报告
服务器·mysql·prometheus
拾忆,想起2 天前
设计模式三大分类完全解析:构建高质量软件的基石
xml·微服务·设计模式·性能优化·服务发现
一枚正在学习的小白2 天前
prometheus监控mysql服务
linux·运维·mysql·prometheus
喵叔哟3 天前
10.消息队列集成
后端·服务发现
拾忆,想起3 天前
设计模式:软件开发的可复用武功秘籍
开发语言·python·算法·微服务·设计模式·性能优化·服务发现
chen_note3 天前
监控——普罗米修斯
grafana·prometheus
闲人编程3 天前
Prometheus监控指标集成指南
prometheus·监控·promql·仪表盘··cncf·codecapsule
木子欢儿4 天前
Prometheus Blackbox域名SSL证书监控并设置AlertManager告警
网络·网络协议·ssl·prometheus
香气袭人知骤暖4 天前
Nacos 服务发现保证机制解析
java·spring·服务发现