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

相关推荐
Elastic 中国社区官方博客21 小时前
从平均值到任意百分位数:Elasticsearch 在 ES|QL 中原生支持指数直方图
大数据·数据库·sql·elasticsearch·搜索引擎·全文检索·prometheus
Elastic 中国社区官方博客1 天前
在 Elasticsearch 中使用原生 PromQL 支持查询 Prometheus 指标
大数据·elasticsearch·搜索引擎·信息可视化·全文检索·prometheus
Elastic 中国社区官方博客1 天前
Elastic 9.4:Workflows 正式发布、Agent Builder 更新,以及 Prometheus / PromQL 支持
运维·数据库·人工智能·elasticsearch·搜索引擎·信息可视化·prometheus
虎头金猫3 天前
监控机不在被监控的机器上,Prometheus怎么跨网络把数据拉过来
运维·服务器·开发语言·网络·云原生·开源·prometheus
四方云6 天前
Kamailio + Prometheus 集成方案(含完整可执行配置)
prometheus
雨辰AI7 天前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking
rKWP8gKv77 天前
Java微服务性能监控:Prometheus与Grafana集成方案
java·微服务·prometheus
江南风月8 天前
WGCLOUD如果使用SQL Server数据库推荐哪个版本
运维·网络·zabbix·运维开发·prometheus
marsh02068 天前
42 openclaw服务发现机制:动态管理微服务实例
ai·服务发现·编程·技术
AI木马人9 天前
8.人工智能实战:大模型服务“看起来正常却突然变慢”?Prometheus + Grafana + GPU 指标构建全链路监控体系
人工智能·grafana·prometheus