如何在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
相关产品推荐
相关产品推荐

