RousselTMLEARNING

Article · Logstash: from discovery to expertise

Logstash in production: persistent queues, DLQ and multiple pipelines

1. Losing nothing: the persistent queue #

Memory or disk.

The problem #

By default, Logstash keeps in-flight events in an in-memory queue (queue.type: memory): a crash loses them. The persistent queue (PQ) writes them to disk between inputs and filters: they survive a restart and absorb spikes when Elasticsearch slows down.

Inputs, persistent queue, filters, output, DLQ.

Configuration #

# config/pipelines.yml
- pipeline.id: web
  path.config: /usr/share/logstash/pipeline/web.conf
  queue.type: persisted
  queue.max_bytes: 4gb          # au-delà : contre-pression vers les inputs
  path.queue: /var/lib/logstash/queue
  dead_letter_queue.enable: true
SettingDefaultRole
queue.typememorymemory or persisted
queue.max_bytes1024mbmaximum size on disk
queue.page_capacity64mbpage file size
queue.checkpoint.writes1024checkpoint frequency
Common mistake: Believing the PQ protects against everything: it replaces neither reliable storage nor a sender able to retry. A UDP input (syslog) still loses whatever arrives during downtime; put Kafka in front if loss is unacceptable.
Good practice: Delivery is "at least once": after a recovery, an event may be indexed twice. Compute a stable ID (fingerprint filter) and pass it as document_id to make writes idempotent.

2. The dead letter queue #

Keeping rejections.

Principle #

When Elasticsearch rejects a document (400 or 404 error, typically a mapping conflict), the elasticsearch output writes it to the DLQ instead of dropping it, along with the reason. You then fix and replay it.

# Pipeline de reprise : lit la DLQ du pipeline « web »
input {
  dead_letter_queue {
    path => "/usr/share/logstash/data/dead_letter_queue"
    pipeline_id => "web"
    commit_offsets => true
  }
}
filter {
  # la raison du rejet : [@metadata][dead_letter_queue][reason]
  mutate { convert => { "status" => "integer" } }
}
output { elasticsearch { hosts => ["http://elasticsearch:9200"] data_stream => true } }
SettingRole
dead_letter_queue.enableenables the DLQ (per pipeline)
dead_letter_queue.max_bytesmaximum size (1024mb by default)
dead_letter_queue.storage_policydrop_newer or drop_older when full
dead_letter_queue.retain.ageretention period (e.g. 7d)
Good to know: Only "permanent" rejections go to the DLQ; transient errors (429, 503) are retried indefinitely by the output: backpressure then protects the data.

3. Multiple pipelines #

Isolating flows.

pipelines.yml #

A single large pipeline mixes flows: one slow filter or failing output blocks everything. pipelines.yml declares several independent pipelines, each with its own workers, queue and configuration.

- pipeline.id: entree
  config.string: |
    input { beats { port => 5044 } }
    output {
      if [event][dataset] == "nginx.access" { pipeline { send_to => ["web"] } }
      else if [event][category] == "authentication" { pipeline { send_to => ["securite"] } }
      else { pipeline { send_to => ["autres"] } }
    }
- pipeline.id: web
  path.config: /etc/logstash/conf.d/web.conf     # input { pipeline { address => "web" } }
  pipeline.workers: 4
- pipeline.id: securite
  path.config: /etc/logstash/conf.d/securite.conf
  queue.type: persisted
An "intake" pipeline distributes to three specialised pipelines.
PatternUse
Distributorone input, one pipeline per data type
Output isolatora slow output (S3 archive) does not block Elasticsearch: each has its pipeline and PQ
Forked paththe same event processed differently for two destinations
Collectorseveral pipelines converge on a shared output

4. Performance #

Workers, batches, JVM.

Settings #

SettingDefaultAdvice
pipeline.workersnumber of coresincrease if CPU is underused and filters are costly
pipeline.batch.size125250 to 1000 for more efficient Elasticsearch outputs (more memory)
pipeline.batch.delay50 msrarely changed
jvm.options (-Xms / -Xmx)1gidentical, 4 to 8 GB is usually enough
curl -s localhost:9600/_node/stats/pipelines?pretty | jq '.pipelines.web.events'
curl -s localhost:9600/_node/hot_threads?human=true | head -40
Good practice: Measure before tuning: compare events.in, events.out and per-filter duration_in_millis in _node/stats to find the costly filter.

📄 Logstash in production: persistent queues, DLQ and multiple pipelines →

My progress

  • ⏱ Estimated time : ≈ 8 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Course Glossary

Logstash

An open-source, server-side data processing pipeline that ingests data from a multitude of sources simultaneously, transforms it, and then sends it to...

Recommended Articles

Logstash best practices: pipelines, performance, reliability and monitoring

Logstash best practices: multiple pipelines, dissect rather than grok, conditionals, persistent q...

Logstash: enrich, test, monitor and deploy on Kubernetes

Enrich with translate, geoip and elasticsearch, consume Kafka, test pipelines, monitor Logstash a...

Logstash: role, pipeline concept and installation

Written version of the video lessons: what Logstash is for, how a pipeline works (inputs, filters...

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...

Logstash: managing plugins and adopting Elastic Common Schema (ECS)

Written version of the video lessons: list, install, update and bundle Logstash plugins offline; ...

Logstash: inputs and outputs

Written version of the video lessons: common inputs (beats, file, tcp/udp, http, kafka, jdbc) and...

Logstash: filters, grok and dissect

Written version of the video lessons: essential filters (mutate, date, json, kv, drop), the grok ...

Elasticsearch on Kubernetes with ECK: deployment, persistent storage and upgrades

Deploy Elasticsearch and Kibana on Kubernetes with Elastic Cloud on Kubernetes (ECK): operator, E...

Machine learning in Elastic: anomaly detection and AIOps

Automatically detect abnormal behaviour: anomaly detection jobs, datafeeds, detectors, influencer...

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!