Fluentbit

  • Omnivector Solutions
Channel Revision Published Runs on
latest/stable 3 11 Apr 2022
Ubuntu 20.04 CentOS 7
latest/candidate 3 24 Mar 2022
Ubuntu 20.04 CentOS 7
latest/edge 3 24 Mar 2022
Ubuntu 20.04 CentOS 7
juju deploy fluentbit
Show information

Platform:

Ubuntu
20.04
CentOS
7

charms.fluentbit.v0.fluentbit

Fluentbit charm libraries.

This library contains two main classes: FluentbitProvider and FluentbitClient. FluentbitProvider class is instantiated in the Fluentbit Server charm, and receives configuration data through a relation to other charms. FluentbitClient class should be instantiated in any charm that wants to ship logs via Fluentbit.

Forwarding logs using Fluentbit

To forward logs from your charm to a centralized place using Fluentbit, instantiate the FluentbitClient() class and handle the relation_created event in your main charm code. In this event, your charm must pass all the configuration parameters necessary to configure Fluentbit: the inputs, the parsers, and the filters.

For example:

class MyCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)

        self._fluentbit = FluentbitClient(self, "fluentbit")

        self.framework.observe(self.on.fluentbit.relation_created,
                               self._fluentbit_relation_created)

    def _fluentbit_relation_created(self, event):
        cfg = [{"input": [("name",     "tail"),
                          ("path",     "/var/log/foo/bar.log"),
                          ("path_key", "filename"),
                          ("tag",      "foo"),
                          ("parser",   "bar")]},
               {"parser": [("name",        "bar"),
                           ("format",      "regex"),
                           ("regex",       "^\[(?<time>[^\]]*)\] (?<log>.*)$"),
                           ("time_key",    "time"),
                           ("time_format", "%Y-%m-%dT%H,%M,%S.%L")]}]
        self._fluentbit.configure(cfg)

The configuration object must be a list of dictionaries. Each dictionary must contain one key. The key must be the section of Fluentbit's processing pipeline. Valid ones are:

  • input
  • filter
  • parser
  • multiline_parser
  • output

The value of each key must be a list of all configuration entries. Each entry is a tuple (or list) of values to be rendered in the configuration files.

Your charm's metadata.yaml should have the Fluentbit relation entry in the requires section:

requires:
      fluentbit:
          interface: fluentbit
FluentbitProvider class

This class receives the configuration data and forwards to the Fluentbit Charm, to rewrite the configuration files and restart the service. This class should only be instantiated by Fluentbit Charm.

Caveats

The charm does not validate the configuration files before restarting the service. It is the charm author's responsibility to ensure the configuration is correct.


class FluentbitConfigurationAvailable

Description

Emitted when configuration is available. None

class FluentbitEvents

Description

Fluentbit emitted events. None

class FluentbitProvider

Description

Implement the provider side of the relation. None

Methods

FluentbitProvider. __init__( self , charm , relation_name: str )

Initialize the service provider.

Arguments

charm

a CharmBase instance that manages this instance of the Fluentbit service.

relation_name

string name of the relation that provides the Fluentbit logging service.

FluentbitProvider. configuration( self )

Get the stored configuration.

Returns

list of dictionaries with the configuration parameters.

class FluentbitClient

A client to relate to a Fluentbit Charm.

Description

This class implements the requires end of the relation, to configure Fluentbit.

The instantiating class must handle the relation_created event to configure Fluentbit:

Methods

FluentbitClient. __init__( self , charm , relation_name: str )

Initialize Fluentbit client.

Arguments

charm

a CharmBase object that manages this FluentbitClient object. Typically this is self in the instantiating class.

relation_name

string name of the relation between charm and the Fluentbit charmed service.

FluentbitClient. configure( self , cfg )

Configure Fluentbit.

Arguments

cfg

a list of stuff to setup. Example: [{"input": [("name", "tail"), ("path", "/var/log/slurm/slurmd.log"), ("path_key", "filename"), ("tag", "slurmd"), ("parser", "slurm")]}, {"parser": [("name", "slurm"), ("format", "regex"), ("regex", "^[(?<time>[^]])] (?<message>.)$"), ("time_key", "time"), ("time_format", "%Y-%m-%dT%H,%M,%S.%L")]},