Metric monitoring with automatic anomaly detection
Project description
detectkit
Metric monitoring with automatic anomaly detection.
detectkit is a Python library for data analysts and engineers to monitor time-series metrics with automatic anomaly detection and alerting. dbt-like project structure and CLI.
Features
- Pure numpy arrays — no pandas dependency in core logic
- Statistical detectors — Z-Score, MAD, IQR, Manual Bounds
- Trend & seasonality handling — seasonality grouping, recency weighting (
half_life), robust linear detrending for slowly drifting metrics - Multi-channel alerting — Mattermost, Slack, Telegram, Email, Webhook
- @mentions — tag users/groups in alerts, each channel formats natively
- Alert lifecycle — consecutive anomalies, cooldown, recovery notifications, no-data alerts
- Project-level error alerts — catch DB outages and pipeline crashes once per run
- Database agnostic — ClickHouse, PostgreSQL, MySQL
- Idempotent — resume from interruptions, no duplicate processing
- CLI —
dtk init,dtk run --select,dtk unlock,dtk clean, tag-based selectors
Installation
pip install detectkit
With database drivers:
pip install detectkit[clickhouse] # ClickHouse
pip install detectkit[all-db] # All databases
Quick Start
CLI (Recommended)
# Create project
dtk init my_monitoring
cd my_monitoring
# Configure database in profiles.yml, then:
dtk run --select cpu_usage
dtk run --select tag:critical
dtk run --select cpu_usage --steps load,detect
dtk run --select cpu_usage --from 2024-01-01
# Clear a stuck lock left by a crashed run (e.g. DB restarted mid-run)
dtk unlock --select cpu_usage
# Prune data orphaned by config edits (dry-run; add --execute to apply)
dtk clean --select cpu_usage
Metric Configuration
# metrics/api_errors.yml
name: api_error_rate
interval: "5min"
query: |
SELECT
toStartOfInterval(timestamp, INTERVAL 5 MINUTE) AS timestamp,
countIf(status_code >= 500) / count() * 100 AS value
FROM http_requests
WHERE timestamp >= '{{ dtk_start_time }}' AND timestamp < '{{ dtk_end_time }}'
GROUP BY timestamp ORDER BY timestamp
detectors:
- type: mad
params:
threshold: 3.0 # in sigma-equivalents
window_size: 2016 # 7 days of 5-min points
window_weights: exponential # optional: favor recent data
half_life: "1d" # weight halves every day of age
alerting:
enabled: true
channels: [mattermost_ops]
consecutive_anomalies: 3
direction: "up"
mentions: [oncall_engineer, here]
alert_cooldown: "30min"
notify_on_recovery: true
suppress_until: "2026-04-11 18:00:00" # Suppress alerts until this UTC time
Python API
import numpy as np
from detectkit.detectors.statistical import ZScoreDetector
detector = ZScoreDetector(threshold=3.0, window_size=100)
results = detector.detect({
'timestamp': np.array([...], dtype='datetime64[ms]'),
'value': np.array([1.0, 2.0, 1.5, 10.0, 1.8]),
})
for r in results:
if r.is_anomaly:
print(f"Anomaly at {r.timestamp}: {r.value}")
Documentation
- Getting Started — 5-minute quickstart
- Configuration Guide — all config options
- Detectors Guide — choosing the right detector
- Alerting Guide — channels, mentions, cooldown, recovery
- CLI Reference — command-line documentation
- Examples — real-world monitoring scenarios
- Changelog — version history
Requirements
- Python 3.10+
- numpy >= 1.24.0
- pydantic >= 2.0.0
- click >= 8.0
- PyYAML >= 6.0
- Jinja2 >= 3.0
License
MIT License — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file detectkit-0.8.2.tar.gz.
File metadata
- Download URL: detectkit-0.8.2.tar.gz
- Upload date:
- Size: 102.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26012cc22a43b768294c11ac11fe3b238ea79a58902f465daea4c95a8088bb0e
|
|
| MD5 |
308763d00d41fa9f7827c03041f3c6ab
|
|
| BLAKE2b-256 |
b5f38b7f8948d56b09cb617c318e0e90da2dec37bb710d868dc205b6f6c66029
|
Provenance
The following attestation bundles were made for detectkit-0.8.2.tar.gz:
Publisher:
publish.yml on alexeiveselov92/detectkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
detectkit-0.8.2.tar.gz -
Subject digest:
26012cc22a43b768294c11ac11fe3b238ea79a58902f465daea4c95a8088bb0e - Sigstore transparency entry: 1825833727
- Sigstore integration time:
-
Permalink:
alexeiveselov92/detectkit@f871d39694d6b2e713e16ecf9b3666d35f132104 -
Branch / Tag:
refs/tags/v0.8.2 - Owner: https://github.com/alexeiveselov92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f871d39694d6b2e713e16ecf9b3666d35f132104 -
Trigger Event:
push
-
Statement type:
File details
Details for the file detectkit-0.8.2-py3-none-any.whl.
File metadata
- Download URL: detectkit-0.8.2-py3-none-any.whl
- Upload date:
- Size: 134.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9124c2380e32376e461f4d596b8eb4345384afa8c9e922669f485a9dfe3c8316
|
|
| MD5 |
d510848aad5c1da36f2208d9c44d74b7
|
|
| BLAKE2b-256 |
4814deb2ae4aa956f63bfa6c7470c6171b19fd934ebdb5dc190c45fafe47995d
|
Provenance
The following attestation bundles were made for detectkit-0.8.2-py3-none-any.whl:
Publisher:
publish.yml on alexeiveselov92/detectkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
detectkit-0.8.2-py3-none-any.whl -
Subject digest:
9124c2380e32376e461f4d596b8eb4345384afa8c9e922669f485a9dfe3c8316 - Sigstore transparency entry: 1825833978
- Sigstore integration time:
-
Permalink:
alexeiveselov92/detectkit@f871d39694d6b2e713e16ecf9b3666d35f132104 -
Branch / Tag:
refs/tags/v0.8.2 - Owner: https://github.com/alexeiveselov92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f871d39694d6b2e713e16ecf9b3666d35f132104 -
Trigger Event:
push
-
Statement type: