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

请求Fluentd示例:从指定Prometheus URI采集数据至RabbitMQ

Fluentd配置示例:采集Prometheus URI数据并推送至RabbitMQ

根据你的需求,分两种常见场景给出配置方案:


场景1:Fluentd主动拉取Prometheus API数据

如果需要定时从Prometheus的查询接口拉取JSON数据,推荐使用http_poll插件(需先安装):

1. 安装依赖插件

在Fluentd容器内执行:

gem install fluent-plugin-http-poll

如果是Docker部署,建议把安装步骤写入Dockerfile,避免每次启动重复安装:

FROM fluent/fluentd:v1.16-debian-1
USER root
RUN gem install fluent-plugin-http-poll
USER fluent

2. 完整配置文件(fluent.conf)

# 定时拉取Prometheus API数据的Source
<source>
  @type http_poll
  tag prometheus.query  # 自定义标签,用于后续匹配
  url "http://your-prometheus-ip:9090/api/v1/query?query=cadvisor_version_info&time=${Time.now.to_f}"
  interval 60  # 拉取间隔(秒),可按需调整
  response_type json  # 指定返回数据为JSON格式
  # 若Prometheus需认证,添加以下headers配置
  # headers {"Authorization" => "Bearer your-auth-token"}
</source>

# 推送至RabbitMQ的Match规则
<match prometheus.query>
  @type rabbitmq
  host rabbitmq
  port 5672
  user guest
  password guest
  vhost /
  exchange testlogexch
  exchange_type topic
  exchange_durable true
  routing_key testlogkey
  heartbeat 60
</match>

注:${Time.now.to_f}会自动替换为当前时间戳,实现动态时间参数查询。


场景2:接收外部发送至Fluentd的Prometheus风格请求

如果是其他服务将数据POST到Fluentd的/api/v1/query?xxx路径,只需调整原有HTTP Source配置即可:

调整后的fluent.conf

<source>
  @type http
  port 9090
  bind my-ip-addr
  tag api.${path}  # 根据请求路径生成标签,便于区分不同接口
  format json  # 指定请求体为JSON格式
</source>

# 匹配所有api开头的标签,推送至RabbitMQ
<match api.**>
  @type rabbitmq
  host rabbitmq
  port 5672
  user guest
  password guest
  vhost /
  exchange testlogexch
  exchange_type topic
  exchange_durable true
  routing_key testlogkey
  heartbeat 60
</match>

该配置会接收任意路径的HTTP POST请求,自动解析请求体中的JSON数据,并按规则推送至RabbitMQ。


内容的提问来源于stack exchange,提问作者niraimathi k g c

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 12:05:13