监控

从 Fluent Bit 收集指标

Fluent Bit 带有内置的 HTTP 服务,可用于查询内部信息并监控每个正在运行的插件的指标。

监控接口可以轻松地与 Prometheus 集成,因为我们支持 Prometheus 原生格式。

快速开始

首先,第一步是修改配置文件以启用 HTTP Server:

[SERVICE]
    HTTP_Server  On
    HTTP_Listen  0.0.0.0
    HTTP_PORT    2020

[INPUT]
    Name cpu

[OUTPUT]
    Name  stdout
    Match *

上面的配置代码片段将指示 Fluent Bit 在 TCP/2020 端口上启动 HTTP Server 并在所有网络接口上进行监听:

$ bin/fluent-bit -c fluent-bit.conf
Fluent Bit v1.4.0
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2020/03/10 19:08:24] [ info] [engine] started
[2020/03/10 19:08:24] [ info] [http_server] listen iface=0.0.0.0 tcp_port=2020

现在使用简单 curl 命令就可以收集一些信息:

请注意,我们正在将 curl 命令输出发送到 jq 程序,这有助于从终端读取 JSON 数据。Fluent Bit 并非旨在进行 JSON 优雅打印。

REST API Interface

Fluent Bit 公开了许多有用的监控接口,从 Fluent Bit v0.14 开始,以下端点可用:

URI

Description

Data Format

/

Fluent Bit 构建信息

JSON

/api/v1/uptime

以秒和可读的格式获取正常运行的时间

JSON

/api/v1/metrics

已加载插件的内部指标

JSON

/api/v1/metrics/prometheus

可以被 Prometheus 服务获取已加载插件的内部指标

Prometheus Text 0.0.4

Uptime Example

使用以下命令查询服务正常运行时间:

它应该打印类似如下的输出:

Metrics Examples

使用以下命令查询 JSON 格式的内部指标:

it should print a similar output like this:

Metrics in Prometheus format

查询 Prometheus Text 0.0.4 格式的内部指标:

这次,相同的指标将以 Prometheus 格式输出,而不是 JSON

配置别名

默认情况下,在运行时配置的插件会以 plugin_name.ID 的格式获取内部名称。出于监控目的,如果配置了多个相同类型的插件,可能会造成混淆。为了区别,每个配置的输入或输出部分都可以使用别名,它将用作指标的父名称。

下面的示例使用 CPU 输入插件的 INPUT 部分设置别名:

当查询指标时,我们获取到了设置的别名而不是插件的名称:

Last updated

Was this helpful?