Elasticsearch Logstash and Beats
Elasticsearch stores and searches data, but it does not go out and fetch that data. Something must collect log files, system metrics, and network events from many machines and deliver them. Beats and Logstash fill this role. Beats are small collectors that run on each server. Logstash is a heavier processing engine that cleans and reshapes data in transit.
Servers Collection and processing Storage
[Web server] + Filebeat ─┐
[App server] + Filebeat ─┼─→ Logstash ─→ Elasticsearch ─→ Kibana
[Database] + Metricbeat┘ (parse, enrich)
What Beats Do
Beats are lightweight agents written in Go. Each one watches a specific kind of data and ships it onward. Their small size lets them run on every machine without slowing it down.
| Beat | Collects |
|---|---|
| Filebeat | Log files |
| Metricbeat | CPU, memory, disk, and service statistics |
| Packetbeat | Network traffic details |
| Winlogbeat | Windows event logs |
| Auditbeat | File changes and user activity |
| Heartbeat | Uptime checks for websites and services |
A Filebeat Configuration
Filebeat reads settings from filebeat.yml. The example below follows log files and sends events to Elasticsearch.
filebeat.inputs:
- type: filestream
id: web-logs
paths:
- /var/log/nginx/access.log
output.elasticsearch:
hosts: ["https://localhost:9200"]
api_key: "id:api_key_value"
ssl.certificate_authorities: ["/etc/filebeat/http_ca.crt"]
Filebeat remembers its position in each file. A restart resumes where the agent stopped, so no lines repeat or vanish.
What Logstash Does
Logstash runs pipelines made of three stages: inputs read data, filters transform it, and outputs write it. A pipeline file describes all three stages.
INPUT FILTER OUTPUT
beats ──→ parse text into fields ──→ elasticsearch
file fix dates and types
kafka remove or add fields
A Complete Pipeline Example
input {
beats {
port => 5044
}
}
filter {
grok {
match => { "message" => "%{IPORHOST:client} %{WORD:method} %{URIPATH:path} %{NUMBER:status}" }
}
date {
match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
}
mutate {
convert => { "status" => "integer" }
remove_field => ["message"]
}
}
output {
elasticsearch {
hosts => ["https://localhost:9200"]
index => "web-logs-%{+YYYY.MM.dd}"
api_key => "id:api_key_value"
}
}
Raw line: 203.0.113.7 GET /pricing 200
After grok: client: "203.0.113.7"
method: "GET"
path: "/pricing"
status: 200
The grok filter turns an unstructured line into searchable fields. Patterns such as IPORHOST and NUMBER come from a built-in library, so common formats need little custom work.
Useful Filter Plugins
| Filter | Purpose |
|---|---|
| grok | Extracts fields from text using patterns |
| date | Reads timestamps and sets the event time |
| mutate | Renames, converts, adds, or removes fields |
| geoip | Adds location details for an IP address |
| useragent | Breaks a browser string into name and version |
| json | Parses JSON text into fields |
Choosing Between Beats, Logstash, and Ingest Pipelines
| Tool | Strength | Weakness |
|---|---|---|
| Beats alone | Tiny footprint, simple setup | Limited transformation |
| Beats with Logstash | Powerful parsing, many inputs and outputs | Extra servers to run |
| Beats with ingest pipelines | Processing inside Elasticsearch, fewer moving parts | Adds load to ingest nodes |
Many teams skip Logstash and let Beats send data straight to Elasticsearch, using ingest pipelines for parsing. Logstash earns its place when data comes from many unusual sources, needs heavy reshaping, or must reach several destinations at once.
Reliability Features
Logstash offers a persistent queue that stores events on disk before processing. A crash or a slow Elasticsearch no longer loses data. Beats retry delivery and apply back-pressure, which slows collection when the destination falls behind.
logstash.yml:
queue.type: persisted
queue.max_bytes: 4gb
pipeline.workers: 4
Elastic Agent as a Unified Option
Elastic Agent combines the roles of several Beats in a single installed program. Fleet in Kibana manages agents centrally, including policies and upgrades. New deployments often pick this route for easier management, while existing Beats setups continue to work without change.
Testing a Pipeline
Validate configuration before running it, and watch the first events closely.
bin/logstash -f pipeline.conf --config.test_and_exit
bin/logstash -f pipeline.conf
Check the destination index with GET /web-logs-*/_search?size=1 and confirm that each field arrived with the right name and type.
Scaling the Collection Layer
Large environments run several Logstash servers behind a load balancer. Beats spread events across the servers, and each server runs the same pipeline. A message queue such as Kafka can sit between Beats and Logstash to absorb traffic spikes, so a burst of events waits in the queue instead of overwhelming the pipeline.
Beats ──→ Kafka queue ──→ Logstash servers (x3) ──→ Elasticsearch
(buffers bursts)
Monitor the pipeline itself. Logstash exposes statistics through a monitoring API, and Beats report health to Kibana. Track events received, events sent, and queue depth. A rising queue depth means Elasticsearch or the filters cannot keep pace.
