Skip to content

feat: implement usage monitoring with statistical anomaly detection#42

Merged
Daniel Beer (DanielB945) merged 1 commit intomainfrom
monitoring/usage
Mar 10, 2026
Merged

feat: implement usage monitoring with statistical anomaly detection#42
Daniel Beer (DanielB945) merged 1 commit intomainfrom
monitoring/usage

Conversation

@AssafHayEden
Copy link
Copy Markdown
Collaborator

@AssafHayEden Assaf Hay Eden (AssafHayEden) commented Mar 10, 2026

Summary

Autonomous usage monitoring using 3 standard deviation (3σ) statistical anomaly detection.

What Changed

  • Statistical method: 3σ threshold (99.7% confidence)
  • Combined script: SQL query + alerting logic in single usage_monitor.py file (303 lines)
  • Z-score calculations: Compares metrics against last 10 same-day-of-week with mean/stddev
  • Severity levels: WARNING (|z| > 3), CRITICAL (|z| > 4.5)
  • Root cause tool: investigate_root_cause.sql for enterprise org-level drill-down
  • Bi-directional: Detects both increases (feature launches) and decreases (churn)

Files

  • agents/monitoring/usage/SKILL.md (182 lines) - 6-part Agent Skills spec
  • agents/monitoring/usage/usage_monitor.py (303 lines) - Combined SQL + alerting
  • agents/monitoring/usage/investigate_root_cause.sql (85 lines) - Root cause queries

Usage

pip install google-cloud-bigquery
python3 usage_monitor.py  # Monitor yesterday

Benefits

✅ Auto-adaptive thresholds (no manual tuning)
✅ Self-contained script (SQL embedded)
✅ Statistically sound (3σ = 99.7% confidence)
✅ Cleaner documentation (-45% lines)

Part 2/6 of splitting PR #38

🤖 Generated with Claude Code

Major updates:
- Upgrade from 2σ to 3σ threshold (99.7% confidence)
- Combine SQL + Python into single usage_monitor.py script
- Add statistical z-score calculations with mean and stddev
- Implement severity levels: WARNING (|z| > 3), CRITICAL (|z| > 4.5)
- Add investigate_root_cause.sql for enterprise drill-down
- Remove duplication, apply progressive disclosure
- Detect both increases and decreases in usage metrics

Benefits:
- Auto-adaptive thresholds (no manual tuning)
- Self-contained script (SQL embedded in Python)
- Cleaner structure (182 lines vs 335 lines)
- Statistically sound (3σ = 99.7% confidence)
@DanielB945 Daniel Beer (DanielB945) deleted the monitoring/usage branch March 10, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants