You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VictoriaMetrics的azure_sd_config中配置EC2式过滤规则?

问题

之前在AWS平台使用vmagent的scrape_config配置可正常工作,现在迁移至Azure平台,需要筛选带有mon_exporters:node标签的VM来抓取node_exporter指标。查阅VictoriaMetrics官方文档未找到azure_sd_config的filter配置选项,当前配置会拉取订阅下所有VM,想知道有没有实现按需筛选VM的方法。

尝试的配置

- job_name: 'node_exporter'
    honor_timestamps: true
    scrape_interval: 1m
    scrape_timeout: 15s
    metrics_path: /metrics
    scheme: http
    follow_redirects: true
    azure_sd_configs:
    - subscription_id: 'xxxxx'
      authentication_method: 'ManagedIdentity'
      environment: 'AzurePublicCloud'
      refresh_interval: 5m
      port: 9100
      filters:
        - name: 'tag:mon_exporters'
          values: ["*node*"]

解决方案

VictoriaMetrics的azure_sd_config确实没有内置的filter参数,但可以通过添加relabel_configs来实现VM筛选,具体配置如下:

- job_name: 'node_exporter'
    honor_timestamps: true
    scrape_interval: 1m
    scrape_timeout: 15s
    metrics_path: /metrics
    scheme: http
    follow_redirects: true
    azure_sd_configs:
    - subscription_id: 'xxxxx'
      authentication_method: 'ManagedIdentity'
      environment: 'AzurePublicCloud'
      refresh_interval: 5m
      port: 9100
    relabel_configs:
    # 精准匹配标签值为node的VM
    - source_labels: [__meta_azure_machine_tag_mon_exporters]
      regex: node
      action: keep
    # 若需模糊匹配标签值包含node的VM,可替换为以下配置
    # - source_labels: [__meta_azure_machine_tag_mon_exporters]
    #   regex: .*node.*
    #   action: keep

说明

  • VictoriaMetrics会为Azure VM的标签生成对应元标签,格式为__meta_azure_machine_tag_<标签名>,因此mon_exporters标签对应的元标签是__meta_azure_machine_tag_mon_exporters
  • action: keep表示仅保留匹配正则表达式的目标,其余目标会被过滤,以此实现按需筛选

内容的提问来源于stack exchange,提问作者codenamebazinga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 07:35:28