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

相关推荐
JasonChen@6661 天前
prometheus静态监控static_config案例四(10)
grafana·prometheus
JasonChen@6662 天前
prometheus静态监控static_config案例二(8)
grafana·prometheus
JasonChen@6666 天前
prometheus静态监控static_configs案例一(7)
prometheus
lisanmengmeng6 天前
prometheus的rules 配置说明
prometheus
fengkai454510 天前
Prometheus+K8s弹性伸缩综合项目
运维·kubernetes·k8s·prometheus·hpa·vpa
mengge.cloud12 天前
prometheus+k8s+弹性伸缩,综合项目
云原生·容器·kubernetes·prometheus
闲云野鹤在人间13 天前
Prometheus入门|搭建Prometheus+Node‑Exporter+Grafana完整主机监控平台
grafana·prometheus
萧瑟余晖19 天前
Dubbo详解篇四:注册中心与服务发现
服务发现·dubbo
疯子的梦想@23 天前
Prometheus 接入 Alertmanager 与钉钉机器人,附中文模板和完整踩坑记录
机器人·钉钉·prometheus
lbb 小魔仙24 天前
Windows搭建PaddleOCR+飞书Webhook自动打卡通知机器人:识别、推送与远程触发完整教程
数据库·人工智能·prometheus·时序数据库