|
1 | | -# Behavioral Intelligence Layer |
2 | | - |
3 | | -SentraCore moves beyond static thresholds (e.g., "Alert if CPU > 90%") to implement context-aware, statistical analysis of system behavior. |
4 | | - |
5 | | -## 1. Time-of-Day Segmenting |
6 | | -System behavior changes throughout the day. A backup script running at 2 AM might spike the CPU to 100%, which is *normal* for that time, but a spike to 100% at 2 PM might be an anomaly. |
7 | | -We break the day into 4 segments: |
8 | | -- **Night:** 00:00 - 06:00 |
9 | | -- **Morning:** 06:00 - 12:00 |
10 | | -- **Afternoon:** 12:00 - 18:00 |
11 | | -- **Evening:** 18:00 - 24:00 |
12 | | - |
13 | | -The `BaselineModel` stores separate standard deviations and means for each segment. |
14 | | - |
15 | | -## 2. Statistical Anomaly Detection (Z-Scores) |
16 | | -The `AnomalyDetector` evaluates the current snapshot against the active Time-of-Day segment. |
17 | | -- Instead of raw percentages, it calculates the Z-Score: `(Current - Mean) / Standard Deviation`. |
18 | | -- Anomalies must be **sustained** over multiple cycles to trigger an elevated stress response, preventing micro-spikes from causing false alarms. |
19 | | - |
20 | | -## 3. Trend Analysis |
21 | | -The `TrendAnalyzer` performs linear regression over the short-term buffer (last 60 seconds). |
22 | | -- **CPU Slope:** Detects run-away processes before they hit 100%. |
23 | | -- **Memory Slope:** Acts as a real-time memory leak detector. |
24 | | -- **Volatility:** Calculates short-term standard deviation to measure system instability. |
25 | | - |
26 | | -## 4. Multi-State Stress Engine |
27 | | -The final Stress Score (0-100) is a composite of: |
28 | | -1. Raw instantaneous resource pressure. |
29 | | -2. Trend modifiers (growing slopes add penalty points). |
30 | | -3. Anomaly modifiers (sustained z-score deviations multiply the pressure). |
| 1 | +# Intelligence Pipeline |
| 2 | + |
| 3 | +This document explains how SentraCore transforms raw system telemetry into actionable, explainable intelligence across its ten processing stages. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Raw telemetry alone is insufficient for meaningful system monitoring. A CPU reading of 95% could be normal during a scheduled batch job, or it could indicate a runaway process. SentraCore resolves this ambiguity through a sequential intelligence pipeline that layers context, statistics, and forecasting on top of raw data. |
| 10 | + |
| 11 | +``` |
| 12 | +SystemCollector |
| 13 | + → Normalizer (EMA smoothing, spike detection) |
| 14 | + → TimeSeriesBuffer (ring buffers for historical context) |
| 15 | + → BaselineModel (per-segment adaptive learning) |
| 16 | + → TrendAnalyzer (linear regression, slope, volatility) |
| 17 | + → AnomalyDetector (Z-score deviation from baseline) |
| 18 | + → StressEngine (multi-state composite score) |
| 19 | + → PredictionEngine (ETA forecasting, risk scoring) |
| 20 | + → StabilityCalculator (global health index) |
| 21 | + → CorrelationEngine (root cause analysis, triggered on alert) |
| 22 | + → AlertManager (threshold evaluation, RCA attachment) |
| 23 | +``` |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Stage 1: System Collection |
| 28 | + |
| 29 | +**Module:** `engine/collector/system_collector.py` |
| 30 | + |
| 31 | +The `SystemCollector` samples system telemetry at a configurable interval (default: 2 seconds) using `psutil`. Each sample is a `SystemSnapshot` containing CPU percent, memory usage, disk I/O rates, and a UNIX timestamp. |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Stage 2: Normalization |
| 36 | + |
| 37 | +**Module:** `engine/normalization/normalizer.py` |
| 38 | + |
| 39 | +The `Normalizer` applies an **Exponential Moving Average (EMA)** to each metric, reducing the impact of instantaneous spikes on downstream analysis. It also independently detects spikes by comparing raw values against the rolling average. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## Stage 3: Time-Series Buffering |
| 44 | + |
| 45 | +**Module:** `engine/buffer/time_series_buffer.py` |
| 46 | + |
| 47 | +Normalized snapshots are pushed into two ring buffers: |
| 48 | +- **Short-window buffer:** Last ~60 seconds, used for trend analysis. |
| 49 | +- **Long-window buffer:** Last ~30 minutes, used for baseline learning. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Stage 4: Baseline Learning |
| 54 | + |
| 55 | +**Module:** `engine/baseline/baseline_model.py` |
| 56 | + |
| 57 | +The `BaselineModel` learns what is *normal* for the specific machine. It segments the day into four time-of-day windows (Night, Morning, Afternoon, Evening) and maintains a running mean and standard deviation per metric per segment. Static thresholds are never used. |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## Stage 5: Trend Analysis |
| 62 | + |
| 63 | +**Module:** `engine/intelligence/trend_analyzer.py` |
| 64 | + |
| 65 | +The `TrendAnalyzer` performs **linear regression** over the short-window buffer to compute CPU and Memory slope (% change per second) and volatility (short-term standard deviation). A positive, sustained memory slope can indicate a memory leak. |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Stage 6: Anomaly Detection |
| 70 | + |
| 71 | +**Module:** `engine/intelligence/anomaly_detector.py` |
| 72 | + |
| 73 | +The `AnomalyDetector` calculates a Z-Score for each metric against the active time-of-day baseline: |
| 74 | + |
| 75 | +``` |
| 76 | +Z = (Current Value - Baseline Mean) / Baseline Standard Deviation |
| 77 | +``` |
| 78 | + |
| 79 | +Anomalies must be sustained over multiple consecutive cycles before being classified as elevated or severe, preventing transient micro-spikes from generating false alerts. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Stage 7: Multi-State Stress Engine |
| 84 | + |
| 85 | +**Module:** `engine/stress/stress_engine.py` |
| 86 | + |
| 87 | +The `StressEngine` consolidates upstream analysis into a single **Stress Score (0–100)** weighted across three dimensions: |
| 88 | +1. Instantaneous resource pressure (CPU, Memory, Disk). |
| 89 | +2. Trend modifiers (growing slopes add a forward-looking penalty). |
| 90 | +3. Anomaly modifiers (sustained z-score deviations multiply the base pressure). |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Stage 8: Prediction & Risk Engine |
| 95 | + |
| 96 | +**Module:** `engine/intelligence/prediction_engine.py` |
| 97 | + |
| 98 | +The `PredictionEngine` uses EMA-smoothed trend slopes to forecast: |
| 99 | +- **Time-to-Exhaustion (ETA):** Seconds until Memory hits 98% or CPU hits 95%. |
| 100 | +- **Risk Score (0–100%):** Probabilistic assessment of severe degradation within the next 5 minutes. |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## Stage 9: System Stability Index |
| 105 | + |
| 106 | +**Module:** `engine/intelligence/stability_index.py` |
| 107 | + |
| 108 | +The `StabilityCalculator` synthesises all upstream signals into a **System Stability Index (1–100)**. The index is a weighted composite of: |
| 109 | +- **50%** Instantaneous Stress Score |
| 110 | +- **30%** Predictive Risk Score |
| 111 | +- **20%** Anomaly Score |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Stage 10: Correlation & Root Cause Analysis |
| 116 | + |
| 117 | +**Module:** `engine/intelligence/correlation_engine.py` |
| 118 | + |
| 119 | +Invoked lazily only when an alert fires, the `CorrelationEngine` cross-references three data sources: |
| 120 | +1. **Bottleneck Identification:** Determines whether CPU, Memory, or Disk is the primary stressor. |
| 121 | +2. **Suspect Identification:** Cross-references against the `ProcessTracker` to find the top-impact process. |
| 122 | +3. **Trigger Identification:** Cross-references against the `EventLogger` to find the causal system event. |
| 123 | + |
| 124 | +The resulting `RootCauseAnalysis` is attached to the `Alert` and broadcast via WebSocket to the dashboard. |
0 commit comments