Fluent Bit 中文文档
  • Fluent Bit 中文文档
  • 关于
    • Fluent Bit 是什么?
    • Fluent Bit 简要历史
    • Fluentd & Fluent Bit
    • 协议
  • 概念
    • 核心概念
    • 缓冲
    • 数据管道
      • 输入
      • 解析器
      • 过滤器
      • 缓冲
      • 路由
      • 输出
  • 安装
    • 升级说明
    • 平台支持
    • 依赖
    • 源码安装
      • 下载源码
      • 构建和安装
      • 以静态配置构建
    • Linux 软件包
      • Amazon Linux
      • Redhat / CentOS
      • Debian
      • Ubuntu
      • 树莓派
    • Docker
    • Kubernetes
    • Windows
  • 管理
    • 配置 Fluent Bit
      • 格式与模式
      • 配置文件
      • 变量
      • 命令
      • 上游服务负载均衡
      • 单位
    • 安全性
    • 缓冲与存储
    • 积压
    • 调度与重试
    • 内存管理
    • 监控
    • 内部状态导出/信号
  • 数据管道
    • 输入插件
      • Dummy
      • Memory Metics
      • Standard Input
      • Systemd
      • tail
    • 解析器
      • JSON
      • Regular Expression
      • LTSV
      • Logfmt
    • 过滤器
      • Grep
      • Kubernetes
      • Rewrite Tag
      • Modify
      • Nest
    • 输出插件
      • Counter
      • Elasticsearch
      • File
      • FlowCounter
      • HTTP
      • Kafka
      • NULL
      • PostgreSQL
      • Standard Output
      • TCP & TLS
  • 流处理
    • 简介
    • 总览
    • 快速开始
      • Fluent Bit + SQL
      • Check Keys and NULL values
      • Hands On! 101
  • FLUENT BIT FOR DEVELOPERS
    • C Library API
    • 手动提取记录
    • Golang 输出插件
Powered by GitBook
On this page
  • 快速开始
  • REST API Interface
  • Uptime Example
  • Metrics Examples
  • 配置别名

Was this helpful?

  1. 管理

监控

从 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 -s http://127.0.0.1:2020 | jq
{
  "fluent-bit": {
    "version": "0.13.0",
    "edition": "Community",
    "flags": [
      "FLB_HAVE_TLS",
      "FLB_HAVE_METRICS",
      "FLB_HAVE_SQLDB",
      "FLB_HAVE_TRACE",
      "FLB_HAVE_HTTP_SERVER",
      "FLB_HAVE_FLUSH_LIBCO",
      "FLB_HAVE_SYSTEMD",
      "FLB_HAVE_VALGRIND",
      "FLB_HAVE_FORK",
      "FLB_HAVE_PROXY_GO",
      "FLB_HAVE_REGEX",
      "FLB_HAVE_C_TLS",
      "FLB_HAVE_SETJMP",
      "FLB_HAVE_ACCEPT4",
      "FLB_HAVE_INOTIFY"
    ]
  }
}

请注意,我们正在将 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

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

$ curl -s http://127.0.0.1:2020/api/v1/uptime | jq

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

{
  "uptime_sec": 8950000,
  "uptime_hr": "Fluent Bit has been running:  103 days, 14 hours, 6 minutes and 40 seconds"
}

Metrics Examples

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

$ curl -s http://127.0.0.1:2020/api/v1/metrics | jq

it should print a similar output like this:

{
  "input": {
    "cpu.0": {
      "records": 8,
      "bytes": 2536
    }
  },
  "output": {
    "stdout.0": {
      "proc_records": 5,
      "proc_bytes": 1585,
      "errors": 0,
      "retries": 0,
      "retries_failed": 0
    }
  }
}

Metrics in Prometheus format

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

$ curl -s http://127.0.0.1:2020/api/v1/metrics/prometheus

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

fluentbit_input_records_total{name="cpu.0"} 57 1509150350542
fluentbit_input_bytes_total{name="cpu.0"} 18069 1509150350542
fluentbit_output_proc_records_total{name="stdout.0"} 54 1509150350542
fluentbit_output_proc_bytes_total{name="stdout.0"} 17118 1509150350542
fluentbit_output_errors_total{name="stdout.0"} 0 1509150350542
fluentbit_output_retries_total{name="stdout.0"} 0 1509150350542
fluentbit_output_retries_failed_total{name="stdout.0"} 0 1509150350542

配置别名

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

[SERVICE]
    HTTP_Server  On
    HTTP_Listen  0.0.0.0
    HTTP_PORT    2020

[INPUT]
    Name  cpu
    Alias server1_cpu

[OUTPUT]
    Name  stdout
    Alias raw_output
    Match *

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

{
  "input": {
    "server1_cpu": {
      "records": 8,
      "bytes": 2536
    }
  },
  "output": {
    "raw_output": {
      "proc_records": 5,
      "proc_bytes": 1585,
      "errors": 0,
      "retries": 0,
      "retries_failed": 0
    }
  }
}
Previous内存管理Next内部状态导出/信号

Last updated 4 years ago

Was this helpful?

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

CPU