1. Collecting cleanly #
filestream and modules.
Inputs #
# filebeat.yml
filebeat.inputs:
- type: filestream
id: app-logs # identifiant stable obligatoire (suivi de lecture)
paths: [/var/log/app/*.log]
parsers:
- multiline: { type: pattern, pattern: '^\d{4}-\d{2}-\d{2}', negate: true, match: after }
- ndjson: { target: "", add_error_key: true }
prospector.scanner.exclude_files: ['\.gz$']
close.on_state_change.inactive: 5m
filebeat.config.modules: { path: ${path.config}/modules.d/*.yml, reload.enabled: true }filebeat modules list
filebeat modules enable nginx system
filebeat setup -e # templates, dashboards, pipelines d'ingestion
filebeat test config -e && filebeat test outputGood practice: Prefer modules (nginx, mysql, system...): they bring parsing, ECS mappings and ready-to-use dashboards.
2. Making delivery reliable #
Queue and outputs.
Security and resilience #
output.elasticsearch:
hosts: ["https://es01:9200", "https://es02:9200"]
api_key: "${ES_API_KEY}"
ssl.certificate_authorities: ["/etc/filebeat/ca.crt"]
bulk_max_size: 2048
worker: 2
compression_level: 1
queue.disk:
max_size: 5GB # tampon persistant si Elasticsearch est indisponible
path: /var/lib/filebeat/queue
setup.ilm: { enabled: true, policy_name: logs-30j }
logging: { level: warning, to_files: true, files: { keepfiles: 7 } }filebeat keystore create && filebeat keystore add ES_API_KEY
sudo chown root:root /etc/filebeat/filebeat.yml && sudo chmod 600 /etc/filebeat/filebeat.ymlCommon mistake: Without queue.disk, a prolonged Elasticsearch outage can saturate memory or lose events. Size the queue according to throughput × tolerated outage duration.3. Controlling volume and resources #
Less, but better.
Processors and limits #
processors:
- drop_event: { when: { regexp: { message: 'healthcheck' } } }
- drop_fields: { fields: [agent.ephemeral_id, ecs.version, log.offset], ignore_missing: true }
- add_fields: { target: "", fields: { env: prod, team: backend } }
- add_host_metadata: { netinfo.enabled: false }
- rename: { fields: [{ from: "msg", to: "message" }], ignore_missing: true }
# Limiter l'impact sur l'hôte
max_procs: 2
filebeat.registry.flush: 5s
GOMAXPROCS=2 filebeat -e # variable d'environnement# Supervision du Beat lui-même
curl -s localhost:5066/stats | jq '{publié: .libbeat.output.events.acked, erreurs: .libbeat.output.events.failed, file: .libbeat.pipeline.events.active}'
monitoring.enabled: true # envoie les métriques du Beat vers le cluster de monitoring4. Managing agents at scale #
Configuration and evolution.
Operating best practices #
- Deploy the configuration with Ansible, Puppet or Fleet, never by hand.
- A single Beat version per fleet; gradual upgrades (canary).
- Monitor read lag (
log.offsetvs file size) and output errors. - Consider migrating to Elastic Agent or Grafana Alloy if you want to unify logs, metrics and traces.
ansible all -m ansible.builtin.service -a "name=filebeat state=restarted" --limit canary
journalctl -u filebeat --since "10 min ago" | grep -iE "error|ERR"
filebeat export template | head # modèle d'index utiliséReference diagram and quick check #
Visualize the principle and check it from the command line.
Reference diagram #
du -sh /var/lib/filebeat/queue
curl -s localhost:5066/stats | jq '.libbeat.pipeline.queue'