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

相关推荐
heimeiyingwang2 天前
【Prometheus·入门篇】Prometheus 是什么:从 Nagios 到云原生监控的演进
prometheus
秋风点枝3 天前
第一篇:认识 Prometheus —— 云原生监控的基础
云原生·prometheus
名字还没想好☜3 天前
Prometheus 告警实战:写 alerting rules、用 Alertmanager 做路由分组与抑制
运维·前端·javascript·docker·kubernetes·prometheus
SamChan904 天前
用Prometheus+Grafana搭建PDF翻译服务监控看板:指标采集与告警实战
python·ai·pdf·grafana·prometheus·机器翻译
^酸酸4 天前
Prometheus 监控架构部署实战:二进制与 Docker 双方案
docker·架构·prometheus
ylj_dev4 天前
从 0 构建 AI Workload Platform(七):可观测性、故障注入与性能验证
go·prometheus·可观测性·opentelemetry·故障注入
蒲锘5 天前
Devops项目阶段 10:Prometheus 监控与 Alertmanager 邮件告警
prometheus
夜月yeyue5 天前
SOME/IP-SD 服务发现故障
网络·单片机·网络协议·tcp/ip·安全·服务发现
.柒宇.7 天前
运维常见面试题_07_配置管理与监控(Ansible · Prometheus · Alertmanager)· 容器编排(Kubernetes)
运维·k8s·ansible·prometheus
玉&心8 天前
在grafana中引入prometheus的数据监控
grafana·prometheus