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

相关推荐
川石课堂软件测试2 天前
技术分享|JMeter接口与性能测试实战
数据库·功能测试·测试工具·jmeter·单元测试·postman·prometheus
是店小二呀2 天前
Prometheus监控盲区:Pushgateway如何收拢离线任务指标
prometheus
xmlhcxr3 天前
基于 HAProxy+Keepalived 构建高可用 ZrLog 博客系统及监控平台实现(Prometheus + Grafana)
架构·grafana·prometheus
川石课堂软件测试3 天前
软件测试:典型面试题库
数据库·python·功能测试·mysql·单元测试·grafana·prometheus
何中应5 天前
Promehteus如何指定数据路径
运维·prometheus·监控
Elastic 中国社区官方博客5 天前
使用 Remote Write 将 Prometheus 指标发送到 Elasticsearch
大数据·运维·elasticsearch·搜索引擎·全文检索·prometheus
要做一个小太阳5 天前
blockbox配置文件详解与优化
运维·网络·prometheus
Elastic 中国社区官方博客5 天前
Prometheus Remote Write 在 Elasticsearch 中的摄取原理
大数据·数据库·elasticsearch·搜索引擎·信息可视化·全文检索·prometheus
rchmin6 天前
Nacos 3.x 优势介绍及接入指南
微服务·服务发现·动态配置