Drain3 is a Python library for mining log templates from raw log messages, designed for stream processing. It's based on the Drain algorithm and is suitable for real-time log analysis. The library is actively maintained with frequent patch releases, currently at version 0.9.11.
pip install drain3Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Drain3 with a basic configuration, add log messages, and retrieve the identified log clusters. For production use, consider configuring persistence (file, Redis, or HTTP) via `TemplateMinerConfig` to save and load the model state.
Review the official documentation and update imports and configuration instantiation. For example, `config = TemplateMinerConfig()` instead of `config = TemplateMinerConfig.load('config.ini')`, and `from drain3 import Drain3`.Configure a persistence backend (FILE, REDIS, or HTTP) using `TemplateMinerConfig`. Call `drain.save_state()` periodically or upon application shutdown, and `drain.load_state()` upon application startup to ensure state is maintained. Example: `config.persistence_type = 'FILE'; config.file_persistence_path = 'path/to/state.bin'`.
Experiment with `drain_sim_th` and `depth` based on your log data characteristics. A lower `drain_sim_th` (e.g., 0.3-0.4) creates more general templates, while a higher value (e.g., 0.6-0.8) creates more specific ones. `depth` controls how many tokens are considered for tree traversal before a new node is created.