Logstash With Persistent Queue

Better Stack Team
Updated on November 18, 2024

Logstash's persistent queue feature allows it to buffer events to disk in case of network or Elasticsearch downtime, helping to ensure that log data is not lost during temporary outages. This is particularly useful in high-throughput environments where reliability and durability are important.

Setting Up Persistent Queues in Logstash

Here's how you can configure Logstash to use persistent queues:

1. Enable Persistent Queues

  1. Edit the Logstash Configuration File:
    • Open your Logstash configuration file (logstash.yml). This file is typically located in the config directory of your Logstash installation.
  2. Configure Persistent Queues:

    • Add or modify the following settings to enable and configure persistent queues:

       
      queue.type: persisted
      queue.max_bytes: 1gb
      queue.checkpoint.writes: 1024
      queue.checkpoint.interval: 1000
      

      Explanation:

      • queue.type: persisted: Enables the use of persistent queues.
      • queue.max_bytes: Sets the maximum size of the queue. Adjust based on your expected log volume and available disk space.
      • queue.checkpoint.writes: Defines how often Logstash writes queue checkpoints to disk (in number of writes).
      • queue.checkpoint.interval: Sets the interval (in milliseconds) at which checkpoints are written.
  3. Save the Configuration File:

    • Save the changes to logstash.yml.

2. Restart Logstash

  • After modifying the configuration file, restart Logstash to apply the changes:

     
    sudo systemctl restart logstash
    

    Or, if you're using a different method to start Logstash, use the appropriate command to restart it.

3. Verify Persistent Queue Status

  • You can check the status of the persistent queue by examining Logstash logs and using the monitoring APIs. Look for log entries that indicate the persistent queue is in use and verify there are no errors related to queueing.

4. Monitor and Manage Queues

  • Disk Usage: Monitor disk usage to ensure that the persistent queue does not consume excessive disk space.
  • Performance Impact: Be aware that persistent queues can introduce some disk I/O overhead. Monitor performance to ensure that it meets your needs.

Considerations

  1. Disk Space:
    • Ensure you have sufficient disk space for the size of the persistent queue, especially if you expect high log volumes.
  2. Queue Size and Configuration:
    • Adjust the queue size and checkpoint settings based on your specific needs and system performance. Larger queues can accommodate more data but require more disk space.
  3. Recovery:
    • Persistent queues help with recovery after failures, but ensure your overall Logstash and Elasticsearch architecture is designed for resilience.
  4. Performance:
    • While persistent queues enhance durability, they can also introduce some performance overhead due to disk I/O. Monitor and adjust configurations as needed to balance durability and performance.

By setting up persistent queues, you can improve the reliability of your Logstash pipeline and protect against data loss during transient failures.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github