RousselTMLEARNING

Observability

Beats best practices: Filebeat, Metricbeat and reliable collection

Beats best practices: filestream, modules, processors, disk queues, secure outputs, ILM and templates, resource limits, monitoring and configuration management.

1. Collecting cleanly #

filestream and modules.

Inputs #

Beats best practices
A lightweight, safe Beat is better than an agent configured on the fly.
# 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 output
Good 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.yml
Common 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 monitoring

4. 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.offset vs 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 #

Filebeat disk queue
Size the queue according to throughput × tolerated outage duration.
du -sh /var/lib/filebeat/queue
curl -s localhost:5066/stats | jq '.libbeat.pipeline.queue'

Related articles

Beats: Filebeat, Metricbeat, Winlogbeat and their configuration

Written version of the video lessons: role of each Beat, configuration structure, inputs, modules, processors…

Other log sources and queues: syslog, Fluent Bit, Kafka, Redis

Written version of the video lessons: collect syslog, Fluent Bit and other sources, then insert a queue (Kafk…

Beats: going further (security, performance, Elastic Agent and migrating to Alloy)

Industrialize Filebeat, Metricbeat and the other Beats: secure outputs, processors, modules, tuning, monitori…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!