Logstash
repository·main·Indexed 12 days ago
https://github.com/elastic/logstashA 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.
What's inside Logstash
- 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.
Overview of Logstash Integration Tests (RATS)
mainThe 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
-eflag. - 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.
What is Logstash?
mainLogstash 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.
Use the logstash-integration-failure_injector plugin for pipeline testing
mainThe
logstash-integration-failure_injectorplugin is intended exclusively for Logstash pipeline testing purposes. It is not a production plugin.If you are modifying the plugin's source code, you must rebuild the gem file to apply your changes.
gem build logstash-integration-failure_injector.gemspecChoose a monitoring method for Logstash
mainTo 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.
Use the JvmOptionsParser standalone jar for Java 8 compatibility
mainThejvm-options-parseris 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.Choose Logstash plugins for data transformation
mainLogstash 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.
Secure your connection to Elasticsearch
mainLogstash 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:
- Configure authentication credentials for Logstash.
- Grant authorized users permission to access the Logstash indices.
- Enable TLS/SSL in the Elasticsearch output section of your Logstash configuration to allow communication with a secured cluster.
What is a Dead Letter Queue (DLQ) and when to use it
mainA 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
400or404(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.
- Elasticsearch Output: When the Elasticsearch output receives a response code of
What is ECS in Logstash?
mainThe 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.Overview of creating Java plugins for Logstash
mainLogstash supports native Java plugins through a system composed of three main parts:
- Java execution engine extensions: Allows Java plugins to run within Logstash pipelines.
- Java APIs: Found in the
co.elastic.logstash.apipackage. Important: When developing, only reference classes or interfaces within theco.elastic.logstash.apipackage. Referencing concrete implementations outside of this package may cause your plugin to break if Logstash internals change. - Packaging and deployment tooling: Automates the process of preparing your plugin for use in Logstash.
To create a plugin, follow this general workflow:
- Choose a plugin type:
input,codec,filter, oroutput. - Set up your development environment.
- Code the plugin logic.
- Package and deploy the plugin.
- Run Logstash with the new plugin loaded.
Handle plugin shutdown with stop and awaitStop
mainLogstash shuts down output plugins both asynchronously and cooperatively. Your plugin must implement two methods to handle this:
stop(): This method is called to signal that the plugin should stop sending events. A common pattern is to set avolatile boolean stopped = true;flag.awaitStop(): This method is called to block the shutdown process until the plugin has finished its cleanup. Ajava.util.concurrent.CountDownLatchis 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(); }