Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ post: [Use open source Drain3 log-template mining project to monitor for network
#### New features

- [**Persistence**](#persistence). Save and load Drain state into an [Apache Kafka](https://kafka.apache.org)
topic, [Redis](https://redis.io/) or a file.
topic, [Redis](https://redis.io/), [Valkey](https://valkey.io/ )or a file.
- **Streaming**. Support feeding Drain with messages one-be-one.
- [**Masking**](#masking). Replace some message parts (e.g numbers, IPs, emails) with wildcards. This improves the
accuracy of template mining.
Expand Down Expand Up @@ -218,6 +218,8 @@ Drain3 currently supports the following persistence modes:

- **Redis** - The snapshot is saved to a key in Redis database (contributed by @matabares).

- **Valkey** - The snapshot is saved to a key in Valkey database.

- **File** - The snapshot is saved to a file.

- **Memory** - The snapshot is saved an in-memory object.
Expand Down
1 change: 1 addition & 0 deletions drain3/template_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cachetools import LRUCache, cachedmethod

from drain3.drain import Drain, DrainBase, LogCluster
from drain3.jaccard_drain import JaccardDrain
from drain3.masking import LogMasker
from drain3.persistence_handler import PersistenceHandler
from drain3.simple_profiler import SimpleProfiler, NullProfiler, Profiler
Expand Down
34 changes: 34 additions & 0 deletions drain3/valkey_persistence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: MIT

from typing import Optional, Union

import valkey

from drain3.persistence_handler import PersistenceHandler


class ValkeyPersistence(PersistenceHandler):
def __init__(self,
valkey_host: str,
valkey_port: int,
valkey_db: int,
valkey_pass: Optional[str],
is_ssl: bool,
valkey_key: Union[bytes, str, memoryview]) -> None:
self.valkey_host = valkey_host
self.valkey_port = valkey_port
self.valkey_db = valkey_db
self.valkey_pass = valkey_pass
self.is_ssl = is_ssl
self.valkey_key = valkey_key
self.r = valkey.Valkey(host=self.valkey_host,
port=self.valkey_port,
db=self.valkey_db,
password=self.valkey_pass,
ssl=self.is_ssl)

def save_state(self, state: bytes) -> None:
self.r.set(self.valkey_key, state)

def load_state(self) -> Optional[bytes]:
return self.r.get(self.valkey_key)
Loading