Logstash

repository·main·Indexed 12 days ago

https://github.com/elastic/logstash

A server-side data processing pipeline and core component of the Elastic Stack that ingests data from multiple sources, transforms it, and sends it to various destinations. It features an extensible plugin system with over 200 available plugins and supports custom plugin development using JRuby.

Tokens
143.9K
Snippets
445
Records
675
Agent score
96%

What's inside Logstash

  1. What is Logstash?

    main
    Logstash is a server-side data processing pipeline that is part of the Elastic Stack (alongside Elasticsearch, Kibana, and Beats). It functions by ingesting data from multiple sources simultaneously, transforming that data through a pipeline, and sending it to a destination (the "stash"), such as Elasticsearch. Logstash is highly extensible with over 200 available plugins and supports custom plugin development.
  2. Overview of Logstash Integration Tests (RATS)

    main

    The Logstash Integration Tests, also known as RATS, are full integration test sets. They are designed to validate Logstash by:

    • Starting Logstash from a binary.
    • Running configurations using the -e flag.
    • Utilizing external services such as Kafka, Elasticsearch, and Beats.

    The framework is a hybrid system consisting of:

    • Bash scripts: Primarily used for service setup.
    • Ruby service files: Manage service lifecycles.
    • RSpec: Used for all test assertions.
  3. What is Logstash?

    main

    Logstash is an open source data collection engine featuring real-time pipelining capabilities. It is designed to dynamically unify data from disparate sources and normalize it for various destinations.

    Logstash uses a pipeline architecture consisting of:

    • Input plugins: To ingest various types of events.
    • Filter plugins: To enrich and transform data.
    • Output plugins: To send processed data to destinations.
    • Codecs: To simplify the ingestion and processing of data formats.
  4. Choose a monitoring method for Logstash

    main

    To gain insight into the health of Logstash instances, you can use several collection methods. Note that for modern features, dependability, and easier management, using Elastic Agent is recommended over legacy methods.

    Available Collection Methods

    • Elastic Agent collection (Recommended): Elastic Agent collects monitoring data from your Logstash instance and sends it directly to your monitoring cluster. This method ensures the monitoring agent remains active even if the Logstash instance is down, and allows for centralized management via Fleet.
    • Metricbeat collection: Metricbeat collects monitoring data and sends it directly to your monitoring cluster. Like Elastic Agent, the monitoring agent remains active even if the Logstash instance is not running.
    • Legacy collection (Deprecated): Legacy collectors send monitoring data to your production cluster. This method is deprecated and should be avoided in favor of Elastic Agent or Metricbeat.
  5. Use the JvmOptionsParser standalone jar for Java 8 compatibility

    main
    The jvm-options-parser is a standalone JAR designed to provide helpful, fail-fast error messages when Logstash is executed using older versions of Java (specifically Java 8). It ensures that users are immediately notified if their runtime environment does not meet the required Java version requirements.
  6. Choose Logstash plugins for data transformation

    main

    Logstash provides a wide ecosystem of over 200 plugins to process and transform data. Depending on your specific data processing needs, you can categorize your requirements into the following functional areas:

    • Core Operations: Basic data manipulation and processing.
    • Deserializing Data: Converting raw data formats (like JSON or strings) into structured Logstash events.
    • Extracting Fields and Wrangling Data: Pulling specific values out of fields or reshaping existing data.
    • Enriching Data with Lookups: Adding context to events by performing lookups against external or internal data sources.

    For a complete list of all available processing tools, refer to the Filter plugins and Codec plugins documentation.

  7. Secure your connection to Elasticsearch

    main

    Logstash supports authentication and encryption over HTTPS for its Elasticsearch output, input, and filter plugins, as well as for monitoring and centralized pipeline management.

    Starting with Elasticsearch 8.0, clusters are secured by default. To establish communication, you must:

    1. Configure authentication credentials for Logstash.
    2. Grant authorized users permission to access the Logstash indices.
    3. Enable TLS/SSL in the Elasticsearch output section of your Logstash configuration to allow communication with a secured cluster.
  8. What is a Dead Letter Queue (DLQ) and when to use it

    main

    A Dead Letter Queue (DLQ) is a mechanism to temporarily store events that Logstash cannot process, preventing them from blocking the pipeline or being lost.

    When it is triggered:

    • Elasticsearch Output: When the Elasticsearch output receives a response code of 400 or 404 (indicating an event that cannot be retried, such as a mapping error). Note that if the HTTP request itself fails (e.g., Elasticsearch is unreachable), Logstash will retry indefinitely and the DLQ will not be used.
    • Conditional Statements: When an error occurs during the evaluation of a conditional statement (e.g., comparing incompatible types like a string and an integer).

    Each event in the DLQ includes the original event, metadata describing the failure reason, information about the plugin that wrote the event, and a timestamp.

  9. What is ECS in Logstash?

    main
    The Elastic Common Schema (ECS) is an open-source specification that defines a common set of fields for storing event data like logs and metrics. Using ECS allows you to normalize event data, making it easier to analyze, visualize, and correlate data across different sources in Elasticsearch.
  10. Overview of creating Java plugins for Logstash

    main

    Logstash supports native Java plugins through a system composed of three main parts:

    1. Java execution engine extensions: Allows Java plugins to run within Logstash pipelines.
    2. Java APIs: Found in the co.elastic.logstash.api package. Important: When developing, only reference classes or interfaces within the co.elastic.logstash.api package. Referencing concrete implementations outside of this package may cause your plugin to break if Logstash internals change.
    3. Packaging and deployment tooling: Automates the process of preparing your plugin for use in Logstash.

    To create a plugin, follow this general workflow:

    1. Choose a plugin type: input, codec, filter, or output.
    2. Set up your development environment.
    3. Code the plugin logic.
    4. Package and deploy the plugin.
    5. Run Logstash with the new plugin loaded.
  11. Handle plugin shutdown with stop and awaitStop

    main

    Logstash shuts down output plugins both asynchronously and cooperatively. Your plugin must implement two methods to handle this:

    1. stop(): This method is called to signal that the plugin should stop sending events. A common pattern is to set a volatile boolean stopped = true; flag.
    2. awaitStop(): This method is called to block the shutdown process until the plugin has finished its cleanup. A java.util.concurrent.CountDownLatch is a recommended way to implement this.

    Note: awaitStop() should not be used to signal the stop; it is only for waiting for the stop to complete.

    private final CountDownLatch done = new CountDownLatch(1);
    private volatile boolean stopped = false;
    
    @Override
    public void stop() {
        stopped = true;
        done.countDown();
    }
    
    @Override
    public void awaitStop() throws InterruptedException {
        done.await();
    }