The ELK Stack (Elasticsearch, Logstash, and Kibana) is a powerful suite for log aggregation and analysis—but by default, it lacks robust alerting features. That’s where ElastAlert comes in. Developed by Yelp, ElastAlert is a simple yet flexible tool to trigger alerts from Elasticsearch query results.
In this tutorial, we’ll walk through how to install ElastAlert and configure a basic alerting rule, helping you monitor your log data in near real-time.
While Kibana now offers basic alerting in newer versions via Kibana Alerting and Watcher, many users still rely on ElastAlert for its:
Before starting, make sure you have the following:
pip
installed
$ git clone https://github.com/Yelp/elastalert.git
$ cd elastalert
$ pip install -r requirements.txt
This index will store alert metadata in Elasticsearch.
$ python elastalert/elastalert.py --config config.yaml --verbose --start NOW
config.yaml
es_host: localhost
es_port: 9200
writeback_index: elastalert_status
buffer_time:
minutes: 15
run_every:
minutes: 1
Tip: Adjust the buffer and run interval based on how frequently your logs are updated.
Save the following as rules/error_alert.yaml
:
name: Error Alert
type: frequency
index: logstash-*
num_events: 3
timeframe:
minutes: 5
filter:
- term:
log.level: "error"
alert:
- "email"
email:
- "alerts@yourdomain.com"
This rule will send an email if three or more error-level logs appear in a 5-minute window.
ElastAlert supports multiple alerting methods, including:
Configuration for each can be added directly into the rule file.
Once configured, run ElastAlert using:
python -m elastalert.elastalert --config config.yaml
To run it as a background service, consider using supervisord
, systemd
, or Docker.
Using ElastAlert with the ELK Stack provides a lightweight, customizable solution for proactive log monitoring. Whether you're tracking error spikes, failed login attempts, or traffic anomalies, ElastAlert can help you act before problems escalate.