使用Prometheus监控Fluent Bit与Fluentd日志收集系统

#作者:程宏斌

1、fluent-bit

Fluent Bit 官方镜像本身就支持导出 Prometheus 指标能力,只需要按需开放即可。

方法一:HTTP Server 导出

详细配置如下:
[SERVICE]
HTTP_Server On # 若存在 HTTP_Server,但状态为Off,改为On
HTTP_Listen 0.0.0.0
HTTP_PORT 2020 # 端口可自行调整
Prometheus 指标导出验证:
curl http://10.0.12.11:2020/api/v2/metrics/prometheus

在这里插入图片描述
方法一监控数据抓取配置:(prometheus)

  • job_name: ‘fluent-bit’
    metrics_path: /api/v2/metrics/prometheus
    static_configs:
    • targets: [‘10.0.12.11:2020’]

方法二:Fluent Bit Metrics 导出

在Fluent Bit配置中添加如下配置:

[INPUT]
    name          fluentbit_metrics
    tag             internal_metrics
    scrape_interval 2
[OUTPUT]
    name            prometheus_exporter
    match           internal_metrics
    host            0.0.0.0
port            2021

Prometheus 指标导出验证:
curl http://10.0.12.11:2021/metrics
在这里插入图片描述
要让 Prometheus 抓取 Fluent Bit 的指标,需要在 Prometheus 的配置文件 prometheus.yml 中添加一个抓取配置(scrape configuration)
方法二监控数据抓取配置:(prometheus)

  - job_name: 'fluent-bit'
    metrics_path: /metrics
    static_configs:
      - targets: ['10.0.12.11:2021']

监控指标

组件监控项名称指标英文名称阈值说明
Fluent-bit内存缓冲区的使用量fluentbit_input_storage_memory_bytes> storage.backlog.mem_limit配置的一半 紧急
Fluent-bit每个输出插件处理错误的次数fluentbit_output_errors_total> 5 严重
Fluent-bit缓冲区的可用容量fluentbit_output_chunk_available_capacity_percent>70% 紧急
Fluent-bit输入插件是否正常输入fluentbit_input_ingestion_paused=!0 紧急
Fluent-bit每个输出插件成功处理的日志总字节数fluentbit_output_proc_bytes_total
Fluent-bit每个输入插件处理的总字节数fluentbit_input_bytes_total

2、fluentd

插件安装

安装fluent-plugin-prometheus:
fluent-gem install fluent-plugin-prometheus
对于td-agent,使用td-agent-gem安装:
sudo td-agent-gem install fluent-plugin-prometheus

数据采集

为了向 Prometheus 公开 Fluentd 指标,我们需要配置三个部分:
步骤 1:使用 Prometheus Filter 插件统计传入记录
步骤2:使用Prometheus输出插件统计传出记录
步骤 3:通过 HTTP 使用 Prometheus 输入插件公开指标

步骤 1:使用 Prometheus Filter 插件统计传入记录
配置该部分以计算每个标签的传入记录:

# source
<source>
  @type forward
  bind 0.0.0.0
  port 24224
</source>

# count the number of incoming records per tag
<filter company.*> #tag
  @type prometheus
  <metric>
    name Fluentd_input_status_num_records_total
    type counter
    desc The total number of incoming records
    <labels>
      tag ${tag}
      hostname ${hostname}
    </labels>
  </metric>
</filter>

通过此配置,prometheus过滤器插件会在记录进入时开始添加内部计数器。

步骤2:使用Prometheus输出插件统计传出记录
copy使用输出插件配置插件prometheus来计算每个标签的传出记录:

# count the number of outgoing records per tag
<match company.*> #tag
  @type copy
  <store>
    @type forward
    <server>
      name myserver1
      host 192.168.1.3
      port 24224
      weight 60
    </server>
  </store>

  <store>
    @type prometheus
    <metric>
      name Fluentd_output_status_num_records_total
      type counter
      desc The total number of outgoing records
      <labels>
        tag ${tag}
        hostname ${hostname}
      </labels>
    </metric>
  </store>
</match>

通过此配置,prometheus输出插件会在记录发出时开始添加内部计数器。

步骤 3:通过 HTTP 使用 Prometheus 输入插件公开指标
配置prometheus输入插件以通过 HTTP 公开内部计数器信息:

# expose metrics in prometheus format
<source>
  @type prometheus
  bind 0.0.0.0
  port 24231
  metrics_path /metrics
</source>
<source>
  @type prometheus_output_monitor
  interval 10
  <labels>
    hostname ${hostname}
  </labels>
</source>

我们让Fluentd正常采集发送一些日志之后,访问http://localhost:24231/metrics接收指标:
在这里插入图片描述

prometheus配置

  - job_name: 'Fluentd'
    metrics_path: /metrics
    static_configs:
      - targets: ['192.168.1.100:24231']

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值