Fluent Bit: recolección ligera de logs en producción

Flujo de datos en cascada sobre pantalla oscura representando recolección de logs

Fluent Bit es el agente de logs ligero del ecosistema Fluentd. Proyecto CNCF graduado, escrito en C, binario de ~1.5MB, consumo de ~10-30MB RAM en operación. Para equipos que consideran Promtail, Vector, o Datadog agent, Fluent Bit es una opción seria — especialmente en nodos con restricciones de recursos o alta densidad.

Qué lo hace especial

Características prácticas:

  • Tamaño ultra-pequeño: binario de ~1.5MB, imagen Docker <20MB.
  • Muy bajo consumo: 10-30MB RAM en idle, buffering incluido.
  • Performance: ~100k eventos/segundo por nodo sin drama.
  • Cientos de plugins: inputs, parsers, filters, outputs.
  • CNCF graduated: mantenimiento serio, no proyecto hobby.
  • Multi-destination: envía a 1+ output simultáneos.

Arquitectura

Flujo típico:

[INPUTS] → [PARSERS] → [FILTERS] → [OUTPUTS]
  • INPUTS: tail file, systemd, kubernetes, tcp, syslog.
  • PARSERS: regex, JSON, logfmt, apache, nginx, etc.
  • FILTERS: modify, grep, lua, kubernetes enricher.
  • OUTPUTS: Loki, Elasticsearch, Kafka, S3, Splunk, HTTP, stdout.

Configuración básica

[SERVICE]
    Flush        5
    Log_Level    info
    Parsers_File parsers.conf

[INPUT]
    Name              tail
    Path              /var/log/containers/*.log
    Parser            docker
    Tag               kube.*
    Refresh_Interval  10

[FILTER]
    Name                kubernetes
    Match               kube.*
    Kube_URL            https://kubernetes.default.svc:443
    Merge_Log           On

[OUTPUT]
    Name          loki
    Match         *
    Host          loki.monitoring.svc.cluster.local
    Port          3100
    Labels        job=fluentbit, cluster=prod

Setup simple en un archivo de configuración.

Instalación

Docker

docker run -d --name fluentbit \
  -v /var/log:/var/log \
  -v $(pwd)/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf \
  fluent/fluent-bit:latest

Kubernetes DaemonSet

El helm chart oficial simplifica el despliegue:

helm repo add fluent https://fluent.github.io/helm-charts
helm install fluent-bit fluent/fluent-bit \
  --namespace logging \
  --create-namespace \
  --set config.outputs="[OUTPUT]\n  Name loki\n  Match *\n  Host loki.svc\n  Port 3100"

Un pod por nodo, lee de los logs de containers.

Binario directo

curl -LO https://github.com/fluent/fluent-bit/releases/latest/download/fluent-bit-linux-amd64.tar.gz
tar xzf fluent-bit-linux-amd64.tar.gz
./fluent-bit-*/bin/fluent-bit -c config.conf

Outputs populares

Loki

[OUTPUT]
    Name        loki
    Match       *
    Host        loki.example.com
    Port        3100
    Labels      job=app, env=$env
    Line_Format json

Para Grafana Loki stack.

Elasticsearch / OpenSearch

[OUTPUT]
    Name          es
    Match         *
    Host          es.example.com
    Port          9200
    Logstash_Format On
    Retry_Limit   5

S3 (archival)

[OUTPUT]
    Name                  s3
    Match                 *
    bucket                my-logs
    region                eu-west-1
    s3_key_format         /logs/%Y/%m/%d/%H/%M/%S-$UUID.gz
    upload_timeout        10m
    compression           gzip

Ideal para archive barato. S3 Glacier para long-term.

Múltiples destinos

[OUTPUT]
    Name loki
    Match *
    ...

[OUTPUT]
    Name s3
    Match *
    ...

[OUTPUT]
    Name kafka
    Match security.*
    ...

Fluent Bit despacha el mismo log a todos. Fan-out simple.

Filtros útiles

Kubernetes enrichment

[FILTER]
    Name                kubernetes
    Match               kube.*
    Kube_URL            https://kubernetes.default.svc:443
    Merge_Log           On
    K8S-Logging.Parser  On
    K8S-Logging.Exclude Off

Añade namespace, pod, container, labels a cada log event. Imprescindible en K8s.

Grep/exclude

[FILTER]
    Name    grep
    Match   *
    Exclude log healthcheck

Modify (añadir/quitar fields)

[FILTER]
    Name  modify
    Match *
    Add   environment production
    Remove sensitive_field

Lua

Para lógica compleja, filtro Lua permite scripting:

[FILTER]
    Name    lua
    Match   *
    Script  enrich.lua
    Call    add_metadata

Parsers

Regex para logs custom:

[PARSER]
    Name        my_app
    Format      regex
    Regex       ^(?<time>[^ ]*) (?<level>[^ ]*) (?<message>.*)$
    Time_Key    time
    Time_Format %Y-%m-%dT%H:%M:%S

JSON parsers son triviales:

[PARSER]
    Name        json
    Format      json

Fluent Bit vs alternatives

Aspecto Fluent Bit Promtail Vector Filebeat
Tamaño binario ~1.5MB ~10MB ~50MB ~30MB
Memoria idle 10-30MB 30-100MB 50-200MB 80-200MB
Lenguaje C Go Rust Go
Outputs soportados Muchos Loki-focused Muchos Elastic-focused
Ecosistema CNCF Grafana Datadog Elastic
Curva aprendizaje Media Baja Media Media

Fluent Bit es el más ligero. Promtail es simple si usas Loki. Vector es más flexible pero pesado. Filebeat para Elastic stack.

Casos donde elegir Fluent Bit

  • Edge devices con recursos limitados.
  • High-density Kubernetes (muchos pods por nodo).
  • Multi-destination routing necesario.
  • Plugin ecosystem amplio importante.
  • Integración con Fluentd (si tienes backend Fluentd existente).

Observabilidad de Fluent Bit mismo

Fluent Bit expone métricas Prometheus:

[SERVICE]
    HTTP_Server  On
    HTTP_Listen  0.0.0.0
    HTTP_Port    2020

Scrape desde Prometheus para:

  • Eventos procesados por input/output.
  • Buffer usage.
  • Errores de conexión.
  • Latencias de flush.

Troubleshooting

Patrones comunes:

  • Buffer full: aumentar mem_buf_limit o storage.type filesystem.
  • TLS errors con Loki: verificar certs, SNI.
  • Parse errors: logs mal formateados llegan sin parse.
  • High CPU: regex ineficientes en parsers custom.
  • Kubernetes filter no enriquece: permisos RBAC.

Conclusión

Fluent Bit es la opción por defecto razonable para recolección de logs en clusters Kubernetes y edge devices. Su tamaño pequeño y eficiencia lo hacen superar a alternativas pesadas en escenarios con restricciones. Su ecosistema de plugins cubre casos diversos. Para equipos que usan Loki simplemente, Promtail es competitivo; para cualquier cosa más, Fluent Bit gana. CNCF graduation es garantía de continuidad. Adoptar Fluent Bit en 2024 es decisión segura.

Síguenos en jacar.es para más sobre logs, observabilidad y agentes ligeros.

Entradas relacionadas