Fluent Bit: Official Manual
SlackGitHubCommunity MeetingsSandbox and LabsWebinars
4.0
4.0
  • Fluent Bit Documentation
  • About
    • What is Fluent Bit?
    • A Brief History of Fluent Bit
    • Fluentd and Fluent Bit
    • License
    • Sandbox and Lab Resources
  • Concepts
    • Key Concepts
    • Buffering
    • Data Pipeline
      • Input
      • Parser
      • Filter
      • Buffer
      • Router
      • Output
  • Installation
    • Getting Started with Fluent Bit
    • Upgrade Notes
    • Supported Platforms
    • Requirements
    • Sources
      • Download Source Code
      • Build and Install
      • Build with Static Configuration
    • Linux Packages
      • Amazon Linux
      • Redhat / CentOS
      • Debian
      • Ubuntu
      • Raspbian / Raspberry Pi
    • Docker
    • Containers on AWS
    • Amazon EC2
    • Kubernetes
    • macOS
    • Windows
    • Yocto / Embedded Linux
    • Buildroot / Embedded Linux
  • Administration
    • Configuring Fluent Bit
      • YAML Configuration
        • Service
        • Parsers
        • Multiline Parsers
        • Pipeline
        • Plugins
        • Upstream Servers
        • Environment Variables
        • Includes
      • Classic mode
        • Format and Schema
        • Configuration File
        • Variables
        • Commands
        • Upstream Servers
        • Record Accessor
      • Unit Sizes
      • Multiline Parsing
    • Transport Security
    • Buffering and Storage
    • Backpressure
    • Scheduling and Retries
    • Networking
    • Memory Management
    • Monitoring
    • Multithreading
    • HTTP Proxy
    • Hot Reload
    • Troubleshooting
    • Performance Tips
    • AWS credentials
  • Local Testing
    • Validating your Data and Structure
    • Running a Logging Pipeline Locally
  • Data Pipeline
    • Pipeline Monitoring
    • Inputs
      • Collectd
      • CPU Log Based Metrics
      • Disk I/O Log Based Metrics
      • Docker Events
      • Docker Log Based Metrics
      • Dummy
      • Elasticsearch
      • Exec
      • Exec Wasi
      • Ebpf
      • Fluent Bit Metrics
      • Forward
      • Head
      • Health
      • HTTP
      • Kafka
      • Kernel Logs
      • Kubernetes Events
      • Memory Metrics
      • MQTT
      • Network I/O Log Based Metrics
      • NGINX Exporter Metrics
      • Node Exporter Metrics
      • OpenTelemetry
      • Podman Metrics
      • Process Exporter Metrics
      • Process Log Based Metrics
      • Prometheus Remote Write
      • Prometheus Scrape Metrics
      • Random
      • Serial Interface
      • Splunk
      • Standard Input
      • StatsD
      • Syslog
      • Systemd
      • Tail
      • TCP
      • Thermal
      • UDP
      • Windows Event Log
      • Windows Event Log (winevtlog)
      • Windows Exporter Metrics
    • Parsers
      • Configuring Parser
      • JSON
      • Regular Expression
      • LTSV
      • Logfmt
      • Decoders
    • Processors
      • Content Modifier
      • Labels
      • Metrics Selector
      • OpenTelemetry Envelope
      • Sampling
      • SQL
      • Filters as processors
      • Conditional processing
    • Filters
      • AWS Metadata
      • CheckList
      • ECS Metadata
      • Expect
      • GeoIP2 Filter
      • Grep
      • Kubernetes
      • Log to Metrics
      • Lua
      • Parser
      • Record Modifier
      • Modify
      • Multiline
      • Nest
      • Nightfall
      • Rewrite Tag
      • Standard Output
      • Sysinfo
      • Throttle
      • Type Converter
      • Tensorflow
      • Wasm
    • Outputs
      • Amazon CloudWatch
      • Amazon Kinesis Data Firehose
      • Amazon Kinesis Data Streams
      • Amazon S3
      • Azure Blob
      • Azure Data Explorer
      • Azure Log Analytics
      • Azure Logs Ingestion API
      • Counter
      • Dash0
      • Datadog
      • Dynatrace
      • Elasticsearch
      • File
      • FlowCounter
      • Forward
      • GELF
      • Google Chronicle
      • Google Cloud BigQuery
      • HTTP
      • InfluxDB
      • Kafka
      • Kafka REST Proxy
      • LogDNA
      • Loki
      • Microsoft Fabric
      • NATS
      • New Relic
      • NULL
      • Observe
      • OpenObserve
      • OpenSearch
      • OpenTelemetry
      • Oracle Log Analytics
      • PostgreSQL
      • Prometheus Exporter
      • Prometheus Remote Write
      • SkyWalking
      • Slack
      • Splunk
      • Stackdriver
      • Standard Output
      • Syslog
      • TCP and TLS
      • Treasure Data
      • Vivo Exporter
      • WebSocket
  • Stream Processing
    • Introduction to Stream Processing
    • Overview
    • Changelog
    • Getting Started
      • Fluent Bit + SQL
      • Check Keys and NULL values
      • Hands On 101
  • Fluent Bit for Developers
    • C Library API
    • Ingest Records Manually
    • Golang Output Plugins
    • WASM Filter Plugins
    • WASM Input Plugins
    • Developer guide for beginners on contributing to Fluent Bit
Powered by GitBook
On this page
  • Workflow
  • Data types
  • API reference
  • Library context creation
  • Set service properties
  • Enable input plugin instance
  • Set input plugin properties
  • Enable output plugin instance
  • Set output plugin properties
  • Start Fluent Bit engine
  • Prototype
  • Return value
  • Usage
  • Stop Fluent Bit engine
  • Prototype
  • Return value
  • Usage
  • Destroy library context
  • Prototype
  • Return value
  • Usage
  • Ingest data manually
  • Prototype
  • Return value
  • Usage

Was this helpful?

Export as PDF
  1. Fluent Bit for Developers

C Library API

Fluent Bit is written in C and can be used from any C or C++ application.

Workflow

Fluent Bit runs as a service, which means that the exposed API provides interfaces to create and manage contexts, specify inputs and outputs, set configuration parameters, and set routing paths for events or records. A typical usage of this library involves:

  • Creating library instance and contexts and setting their properties.

  • Enabling input plugins and setting their properties.

  • Enabling output plugins and setting their properties.

  • Starting the library runtime.

  • Optionally ingesting records manually.

  • Stopping the library runtime.

  • Destroying library instances and contexts.

Data types

There is only one data type exposed by the library. By convention, this data type is prefixed with flb_.

Type
Description

flb_ctx_t

Main library context. This references the context returned by flb_create();.

API reference

Library context creation

Use the flb_create() function to create library context.

Prototype

flb_ctx_t *flb_create();

Return value

On success, this function returns the library context. On error, it returns NULL.

Usage

flb_ctx_t *ctx;

ctx = flb_create();
if (!ctx) {
    return NULL;
}

Set service properties

Use the flb_service_set() function to set context properties.

Prototype

int flb_service_set(flb_ctx_t *ctx, ...);

Return value

On success, this function returns 0. On error, it returns a negative number.

Usage

This function sets one or more properties as a key/value string. For example:

int ret;

ret = flb_service_set(ctx, "Flush", "1", NULL);

This example specified the values for the property Flush. Its value is always a string (char *), and after all parameters are listed, you must add a NULL argument at the end of the list.

Enable input plugin instance

The Fluent Bit library contains several input plugins. To enable an input plugin, use the flb_input() function to create an instance of it.

For plugins, an instance means a context of the plugin enabled. You can create multiple instances of the same plugin.

Prototype

int flb_input(flb_ctx_t *ctx, char *name, void *data);

The argument ctx represents the library context created by flb_create(), and name is the name of the input plugin to enable.

The argument data can be used to pass a custom reference to the plugin instance. This is mostly used by custom or third-party plugins. For generic plugins, it's okay to pass NULL.

Return value

On success, this function returns an integer value greater than or equal to zero, similar to a file descriptor. On error, it returns a negative number.

Usage

int in_ffd;

in_ffd = flb_input(ctx, "cpu", NULL);

Set input plugin properties

A plugin instance created through flb_input() can include configuration properties. Use the flb_input_set() function to set these properties.

Prototype

int flb_input_set(flb_ctx_t *ctx, int in_ffd, ...);

Return value

On success, this function returns 0. On error, it returns a negative number.

Usage

This function sets one or more properties as a key/value string. For example:

int ret;

ret = flb_input_set(ctx, in_ffd,
                    "tag", "my_records",
                    "ssl", "false",
                    NULL);

The argument ctx represents the library context created by flb_create(). The previous example specified the values for the properties tag and ssl. Its value is always a string (char *), and after all parameters are listed, you must add a NULL argument at the end of the list.

The properties allowed per input plugin are specified in the documentation for each plugin.

Enable output plugin instance

The Fluent Bit library contains several output plugins. To enable an output plugin, use the flb_output() function to create an instance of it.

For plugins, an instance means a context of the plugin enabled. You can create multiple instances of the same plugin.

Prototype

int flb_output(flb_ctx_t *ctx, char *name, void *data);

The argument ctx represents the library context created by flb_create(), and name is the name of the output plugin to enable.

The argument data can be used to pass a custom reference to the plugin instance. This is mostly used by custom or third-party plugins. For generic plugins, it's okay to pass NULL.

Return value

On success, this function returns the output plugin instance. On error, it returns a negative number.

Usage

int out_ffd;

out_ffd = flb_output(ctx, "stdout", NULL);

Set output plugin properties

A plugin instance created through flb_output() can include configuration properties. Use the flb_output_set() function to set these properties.

Prototype

int flb_output_set(flb_ctx_t *ctx, int out_ffd, ...);

Return value

On success, this function returns and integer value greater than or equal to zero, similar to a file descriptor. On error, it returns a negative number.

Usage

This function sets one or more properties as a key/value string. For example:

int ret;

ret = flb_output_set(ctx, out_ffd,
                     "tag", "my_records",
                     "ssl", "false",
                     NULL);

The argument ctx represents the library context created by flb_create(). The previous example specified the values for the properties tag and ssl. Its value is always a string (char *), and after all parameters are listed, you must add a NULL argument at the end of the list.

The properties allowed per output plugin are specified in the documentation for each plugin.

Start Fluent Bit engine

After you create the library context and set input and output plugin instances, use the flb_start() function to start the engine. After the engine has started, it runs inside a new thread (POSIX thread) without blocking the caller application.

Prototype

int flb_start(flb_ctx_t *ctx);

Return value

On success, this function returns 0. On error, it returns a negative number.

Usage

This function uses the ctx argument, which is a reference to the context created by flb_create().

int ret;

ret = flb_start(ctx);

Stop Fluent Bit engine

To stop a running Fluent Bit engine, use flb_stop().

Prototype

int flb_stop(flb_ctx_t *ctx);

The argument ctx is a reference to the context created by flb_create() and started by flb_start().

When the call is invoked, the engine waits a maximum of five seconds to flush buffers and release any resources in use. A stopped context can be restarted at any time, but without any data on it.

Return value

On success, this function returns 0. On error, it returns a negative number.

Usage

int ret;

ret = flb_stop(ctx);

Destroy library context

You can destroy a library context after it's no longer necessary. A previous flb_stop() call is mandatory. After a library context is destroyed, all associated resources are released.

Prototype

void flb_destroy(flb_ctx_t *ctx);

The argument ctx is a reference to the context created by flb_create().

Return value

This function doesn't return a value.

Usage

flb_destroy(ctx);

Ingest data manually

In some cases, the caller application might want to ingest data into Fluent Bit. You can use the flb_lib_push() function to do so.

Prototype

int flb_lib_push(flb_ctx_t *ctx, int in_ffd, void *data, size_t len);

The first argument is the context created through flb_create(). The in_ffd argument is the numeric reference of the input plugin, which in this case is a lib input plugin. The data argument is a reference to the message to be ingested, and the len argument is the number of bytes to take from it.

Return value

On success, this function returns the number of bytes written. On error, it returns -1.

Usage

Last updated 1 day ago

Was this helpful?

For more information about how to use this function, including examples, see .

Ingest Records Manually