Skip to main content

Time series anomaly detection using Redis TimeSeries and Luminol

Project description

Potoos

Potoos is a lightweight Python library for time series anomaly detection using Redis Time Series and Luminol. Monitor your time series data for anomalies with minimal configuration.

Overview

Potoos combines the power of:

  • Redis Time Series for efficient time series data storage and retrieval
  • Luminol for robust anomaly detection algorithms

This makes it ideal for monitoring metrics, detecting unusual patterns, and identifying outliers in your time series data.

Features

  • 🔄 Seamless Redis TimeSeries Integration: Automatically verifies Redis module availability
  • 🔍 Configurable Time Series Retrieval: Forward or reverse order, with flexible query options
  • 🚨 Anomaly Detection: Uses Luminol's advanced algorithms to identify anomalies
  • 🛠️ Highly Configurable: Customize both time series retrieval and anomaly detection parameters

Requirements

  • Python 3.10+
  • Redis server with the RedisTimeSeries module installed
  • Dependencies:
    • redis-py
    • luminol

Installation

pip install potoos

Ensure your Redis server has the TimeSeries module installed:

# Check if module is installed
redis-cli MODULE LIST | grep timeseries

# If not found, install using Redis Stack or Redis modules

Quick Start

Here's a simple example of how to use Potoos:

from redis import Redis
from potoos.client import PotoosClient
from potoos.models.config import TimeSeriesConfig, AnomalyDetectionConfig

# Connect to Redis
redis_client = Redis(host='localhost', port=6379)

# Initialize Potoos client with default configurations
client = PotoosClient(redis_client)

# Or with custom configurations
client = PotoosClient(
    redis_client=redis_client,
    time_series_config=TimeSeriesConfig(reversed=False, count=1000),
    anomaly_config=AnomalyDetectionConfig(algorithm_name='bitmap_detector')
)

# Monitor a time series key for anomalies
results = client.monitor('metrics:cpu:usage')

# Process the results
if results:
    print(f"Analysis complete. Found {results.meta_data.anomalies_found} anomalies")
    print(f"Analyzed {results.meta_data.data_points_analyzed} data points")
    
    # Print information about each anomaly
    for anomaly in results.anomalies:
        print(f"Anomaly at {anomaly.exact_timestamp}")
        print(f"Anomaly score: {anomaly.anomaly_score}")
        
    # Or access anomaly score in TimeSeries object
    print(f"Anomaly scores: {results.scores}")

    # Access time range analyzed
    time_range = results.meta_data.time_range_analyzed
    print(f"Time range analyzed: {time_range.start} to {time_range.end}")

Configuration

Time Series Configuration

from potoos.models.config import TimeSeriesConfig

# Default values shown
config = TimeSeriesConfig(
    count=None,         # Maximum number of samples to return
    aggregation=None,   # Aggregation type (e.g., 'avg', 'sum', 'min', 'max')
    bucket_size=None,   # Time bucket for aggregation in milliseconds
    filter_by=None,     # Filtering options for labels
    align=None,         # Timestamp alignment control
    start=None,         # Start timestamp
    end=None,           # End timestamp
    reversed=False      # Return results in reverse order when True
)

Anomaly Detection Configuration

from potoos.models.config import AnomalyDetectionConfig

# Default values shown
config = AnomalyDetectionConfig(
    algorithm_name='bitmap_detector',  # Algorithm to use
    score_threshold=None,              # Threshold for anomaly detection
    score_percentile_threshold=None,   # Percentile threshold
    algorithm_params={}                # Additional algorithm parameters
)

How It Works

  1. Initialization: PotoosClient connects to your Redis instance and verifies the TimeSeries module is available
  2. Data Retrieval: When monitoring, it fetches time series data according to your configuration
  3. Anomaly Detection: The retrieved data is analyzed using Luminol's algorithms
  4. Results: You receive detailed information about detected anomalies and analysis metadata

Note on Dependencies

Potoos requires NumPy 1.22.4 or earlier due to Luminol's dependency on the numpy.asscalar() function, which was removed in later versions of NumPy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

potoos-0.1.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

potoos-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file potoos-0.1.1.tar.gz.

File metadata

  • Download URL: potoos-0.1.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for potoos-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ad1bc0b8e46430e43fb5fa9a4d12b1b307e93f297083d6a98640c5d699bd436a
MD5 3e0680c6fde3104560930f7fd6dcf21c
BLAKE2b-256 189220de37d7380490c38789d8ecbed5671a068fbe8ce21455419e103a492d99

See more details on using hashes here.

File details

Details for the file potoos-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: potoos-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for potoos-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ee77d84770c23c7562744fd492332954530844e9fcadf384438c7c576383f33
MD5 46f1c32f65fd9e6ad731ed276605b7a7
BLAKE2b-256 33cca6025a4a84cd79ecc48cef78e4a6469ac9fe93ce13d0d4c399c4c8492eee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page