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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Advanced Analytics Agent Specification
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
The Advanced Analytics Agent provides comprehensive monitoring, custom metrics, role-based reporting, and system health tracking. This module integrates with UI interfaces and backend services for real-time analytics and historical trend analysis.
|
| 5 |
+
|
| 6 |
+
## Configuration
|
| 7 |
+
Analytics configuration is defined in [`docs/configs/analytics_config.json`](./analytics_config.json)
|
| 8 |
+
|
| 9 |
+
## Features
|
| 10 |
+
|
| 11 |
+
### Custom Metrics
|
| 12 |
+
- **User Engagement Score**: Composite metric tracking active user ratios and session duration
|
| 13 |
+
- Formula: `(active_users * avg_session_duration) / total_users`
|
| 14 |
+
- Warning threshold: 0.3
|
| 15 |
+
- Critical threshold: 0.15
|
| 16 |
+
- **API Response Time (P95)**: Performance metric for API latency monitoring
|
| 17 |
+
- Unit: milliseconds
|
| 18 |
+
- Warning threshold: 500ms
|
| 19 |
+
- Critical threshold: 1000ms
|
| 20 |
+
- **Error Rate**: Reliability metric tracking system errors
|
| 21 |
+
- Unit: percentage
|
| 22 |
+
- Warning threshold: 2%
|
| 23 |
+
- Critical threshold: 5%
|
| 24 |
+
- **Resource Utilization**: System metrics for CPU, memory, disk, and network usage
|
| 25 |
+
- Components: cpu, memory, disk, network
|
| 26 |
+
- Warning threshold: 75%
|
| 27 |
+
- Critical threshold: 90%
|
| 28 |
+
|
| 29 |
+
### Notifications
|
| 30 |
+
Multi-channel notification system with severity-based routing:
|
| 31 |
+
- **Email**: Alerts sent to admin and ops team for warning/critical events
|
| 32 |
+
- **Slack**: Critical alerts posted to #analytics-alerts channel
|
| 33 |
+
- **Webhooks**: All severity levels sent to configured webhook endpoint
|
| 34 |
+
- **Rate Limiting**: Maximum 10 notifications per hour with 15-minute cooldown
|
| 35 |
+
|
| 36 |
+
### Role-Based Views
|
| 37 |
+
Four distinct role configurations with tailored permissions and dashboards:
|
| 38 |
+
|
| 39 |
+
#### Administrator
|
| 40 |
+
- **Permissions**: view_all, configure, export, delete
|
| 41 |
+
- **Default Dashboard**: system_overview
|
| 42 |
+
- **Visible Metrics**: All metrics (*)
|
| 43 |
+
|
| 44 |
+
#### Data Analyst
|
| 45 |
+
- **Permissions**: view_all, export
|
| 46 |
+
- **Default Dashboard**: analytics_deep_dive
|
| 47 |
+
- **Visible Metrics**: user_engagement_score, custom_metrics, historical_trends
|
| 48 |
+
|
| 49 |
+
#### Developer
|
| 50 |
+
- **Permissions**: view_technical, export
|
| 51 |
+
- **Default Dashboard**: api_performance
|
| 52 |
+
- **Visible Metrics**: api_response_time_p95, error_rate, system_health
|
| 53 |
+
|
| 54 |
+
#### Read-Only Viewer
|
| 55 |
+
- **Permissions**: view_summary
|
| 56 |
+
- **Default Dashboard**: executive_summary
|
| 57 |
+
- **Visible Metrics**: user_engagement_score
|
| 58 |
+
|
| 59 |
+
### Batch Processing
|
| 60 |
+
Scheduled operations for data aggregation and reporting:
|
| 61 |
+
- **Daily Aggregation**: Runs at 2:00 AM, outputs parquet format, 365-day retention
|
| 62 |
+
- **Weekly Report**: Runs Monday 3:00 AM, generates PDF for leadership
|
| 63 |
+
- **Data Cleanup**: Runs Sunday 1:00 AM, purges data older than 90 days
|
| 64 |
+
|
| 65 |
+
### Historical Analysis
|
| 66 |
+
Advanced analytics capabilities:
|
| 67 |
+
|
| 68 |
+
#### Trend Detection
|
| 69 |
+
- Moving average
|
| 70 |
+
- Exponential smoothing
|
| 71 |
+
- Seasonal decomposition
|
| 72 |
+
|
| 73 |
+
#### Anomaly Detection
|
| 74 |
+
- Isolation forest algorithm
|
| 75 |
+
- Statistical outliers
|
| 76 |
+
- Prophet forecasting
|
| 77 |
+
|
| 78 |
+
#### Forecasting
|
| 79 |
+
- 30-day horizon
|
| 80 |
+
- 95% confidence intervals
|
| 81 |
+
|
| 82 |
+
#### Comparative Analysis
|
| 83 |
+
- Day-over-day
|
| 84 |
+
- Week-over-week
|
| 85 |
+
- Month-over-month
|
| 86 |
+
- Year-over-year
|
| 87 |
+
|
| 88 |
+
### System Health Monitoring
|
| 89 |
+
Real-time monitoring with 30-second intervals:
|
| 90 |
+
|
| 91 |
+
#### Database Monitoring
|
| 92 |
+
- Connection pool status
|
| 93 |
+
- Query performance metrics
|
| 94 |
+
- Replication lag tracking
|
| 95 |
+
|
| 96 |
+
#### Cache Monitoring
|
| 97 |
+
- Hit rate analysis
|
| 98 |
+
- Memory usage tracking
|
| 99 |
+
- Eviction rate monitoring
|
| 100 |
+
|
| 101 |
+
#### Queue Monitoring
|
| 102 |
+
- Queue depth tracking
|
| 103 |
+
- Processing rate analysis
|
| 104 |
+
- Dead-letter queue monitoring
|
| 105 |
+
|
| 106 |
+
#### External Services
|
| 107 |
+
- API availability checks
|
| 108 |
+
- Response time monitoring
|
| 109 |
+
- Rate limit tracking
|
| 110 |
+
|
| 111 |
+
#### Auto-Recovery
|
| 112 |
+
- Service restart capability
|
| 113 |
+
- Cache clearing
|
| 114 |
+
- Resource scaling
|
| 115 |
+
|
| 116 |
+
### API Endpoints
|
| 117 |
+
Base path: `/api/v1/analytics`
|
| 118 |
+
Authentication: Bearer token
|
| 119 |
+
Rate limiting: 100 requests per minute
|
| 120 |
+
|
| 121 |
+
#### GET /metrics
|
| 122 |
+
**Description**: Retrieve current metrics
|
| 123 |
+
**Parameters**:
|
| 124 |
+
- `metric_id`: Specific metric identifier
|
| 125 |
+
- `start_time`: Query start time
|
| 126 |
+
- `end_time`: Query end time
|
| 127 |
+
- `granularity`: Data granularity (minute, hour, day)
|
| 128 |
+
|
| 129 |
+
#### POST/PUT/DELETE /metrics/custom
|
| 130 |
+
**Description**: Manage custom metrics
|
| 131 |
+
**Permissions**: Admin only
|
| 132 |
+
|
| 133 |
+
#### GET /dashboards
|
| 134 |
+
**Description**: Get dashboard configurations for user role
|
| 135 |
+
|
| 136 |
+
#### GET/POST /alerts
|
| 137 |
+
**Description**: Manage alert configurations
|
| 138 |
+
|
| 139 |
+
#### POST /export
|
| 140 |
+
**Description**: Export analytics data
|
| 141 |
+
**Parameters**:
|
| 142 |
+
- `format`: json, csv, parquet, excel
|
| 143 |
+
- `metrics`: Array of metric IDs
|
| 144 |
+
- `date_range`: Date range for export
|
| 145 |
+
|
| 146 |
+
#### GET /health
|
| 147 |
+
**Description**: Get system health status
|
| 148 |
+
**Public**: Yes (no authentication required)
|
| 149 |
+
|
| 150 |
+
#### GET /historical
|
| 151 |
+
**Description**: Access historical analysis and trends
|
| 152 |
+
**Parameters**:
|
| 153 |
+
- `analysis_type`: trends, anomalies, forecast, comparison
|
| 154 |
+
- `metric_id`: Target metric
|
| 155 |
+
- `time_range`: Analysis time range
|
| 156 |
+
|
| 157 |
+
### Failover Logging
|
| 158 |
+
Multi-tier logging system with automatic failover:
|
| 159 |
+
|
| 160 |
+
#### Primary Logger: Elasticsearch
|
| 161 |
+
- Endpoint: `${ELASTICSEARCH_URL}`
|
| 162 |
+
- Index pattern: `analytics-logs-%{+YYYY.MM.dd}`
|
| 163 |
+
|
| 164 |
+
#### Failover Tier 1: CloudWatch
|
| 165 |
+
- Log group: `strategystack-analytics`
|
| 166 |
+
- Retention: 30 days
|
| 167 |
+
|
| 168 |
+
#### Failover Tier 2: File System
|
| 169 |
+
- Path: `/var/log/analytics`
|
| 170 |
+
- Rotation: Daily
|
| 171 |
+
- Max size: 100MB per file
|
| 172 |
+
- Retention: 7 days
|
| 173 |
+
|
| 174 |
+
#### Failover Tier 3: Syslog
|
| 175 |
+
- Endpoint: `${SYSLOG_ENDPOINT}`
|
| 176 |
+
- Protocol: TCP
|
| 177 |
+
|
| 178 |
+
**Health Checks**: 60-second intervals
|
| 179 |
+
**Auto-Failover**: Enabled
|
| 180 |
+
**Log Levels**: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
| 181 |
+
**Structured Logging**: Enabled with correlation IDs and session tracking
|
| 182 |
+
|
| 183 |
+
## Integration Points
|
| 184 |
+
|
| 185 |
+
### UI Components (React)
|
| 186 |
+
|
| 187 |
+
#### MetricsDashboard
|
| 188 |
+
- **Path**: `src/components/analytics/MetricsDashboard.tsx`
|
| 189 |
+
- **Props**: roleId, dateRange, refreshInterval
|
| 190 |
+
- **Description**: Main dashboard showing role-based metrics
|
| 191 |
+
|
| 192 |
+
#### CustomMetricBuilder
|
| 193 |
+
- **Path**: `src/components/analytics/CustomMetricBuilder.tsx`
|
| 194 |
+
- **Permissions**: admin, analyst
|
| 195 |
+
- **Description**: UI for creating and editing custom metrics
|
| 196 |
+
|
| 197 |
+
#### AlertsPanel
|
| 198 |
+
- **Path**: `src/components/analytics/AlertsPanel.tsx`
|
| 199 |
+
- **Realtime**: Yes (WebSocket)
|
| 200 |
+
- **Description**: Real-time alert display
|
| 201 |
+
|
| 202 |
+
#### HistoricalAnalyzer
|
| 203 |
+
- **Path**: `src/components/analytics/HistoricalAnalyzer.tsx`
|
| 204 |
+
- **Features**: trends, forecasting, anomalies
|
| 205 |
+
- **Description**: Trend, forecasting, and anomaly visualization
|
| 206 |
+
|
| 207 |
+
#### SystemHealthMonitor
|
| 208 |
+
- **Path**: `src/components/analytics/SystemHealthMonitor.tsx`
|
| 209 |
+
- **Update Interval**: 10 seconds
|
| 210 |
+
- **Description**: Component status dashboard
|
| 211 |
+
|
| 212 |
+
### Backend Integration
|
| 213 |
+
|
| 214 |
+
#### Strategy Engine
|
| 215 |
+
- Metrics export enabled
|
| 216 |
+
- Event hooks: strategy_execution, performance_update
|
| 217 |
+
|
| 218 |
+
#### User Service
|
| 219 |
+
- Metrics export enabled
|
| 220 |
+
- Event hooks: user_action, session_start, session_end
|
| 221 |
+
|
| 222 |
+
#### Notification Service
|
| 223 |
+
- Alert integration enabled
|
| 224 |
+
- Priority routing enabled
|
| 225 |
+
|
| 226 |
+
### WebSocket Support
|
| 227 |
+
- Real-time metric updates via `${WEBSOCKET_URL}/analytics`
|
| 228 |
+
- Redux state management for UI consistency
|
| 229 |
+
|
| 230 |
+
## Performance Optimization
|
| 231 |
+
|
| 232 |
+
### Caching
|
| 233 |
+
- **Strategy**: Redis
|
| 234 |
+
- **TTL**: 5 minutes (300 seconds)
|
| 235 |
+
- **Cache Warmer**: Enabled
|
| 236 |
+
|
| 237 |
+
### Query Optimization
|
| 238 |
+
- Materialized views for frequently accessed aggregations
|
| 239 |
+
- Parallel query execution
|
| 240 |
+
- Query timeout: 30 seconds
|
| 241 |
+
|
| 242 |
+
### Data Sampling
|
| 243 |
+
- High-cardinality threshold: 10,000 records
|
| 244 |
+
- Sampling rate: 10%
|
| 245 |
+
|
| 246 |
+
## Usage
|
| 247 |
+
|
| 248 |
+
1. **Configure analytics sources**: Edit `docs/configs/analytics_config.json` to customize metrics, alerts, roles, and integration points.
|
| 249 |
+
2. **Enable real-time monitoring**: Deploy UI components and connect to analytics API.
|
| 250 |
+
3. **Set up notifications**: Configure email, Slack, and webhook endpoints for alert delivery.
|
| 251 |
+
4. **Configure historical analysis**: Enable trend detection, anomaly detection, and forecasting as needed.
|
| 252 |
+
5. **Monitor system health**: Use system health endpoint for infrastructure monitoring.
|
| 253 |
+
|
| 254 |
+
## Implementation Status
|
| 255 |
+
|
| 256 |
+
- [x] Configuration schema defined
|
| 257 |
+
- [x] Custom metrics configuration
|
| 258 |
+
- [x] Multi-channel notifications
|
| 259 |
+
- [x] Role-based access control
|
| 260 |
+
- [x] Batch processing schedules
|
| 261 |
+
- [x] Historical analysis features
|
| 262 |
+
- [x] System health monitoring
|
| 263 |
+
- [x] API endpoint definitions
|
| 264 |
+
- [x] Failover logging configuration
|
| 265 |
+
- [x] UI component specifications
|
| 266 |
+
- [x] Backend integration points
|
| 267 |
+
- [x] Performance optimization strategies
|
| 268 |
+
|
| 269 |
+
## Next Steps
|
| 270 |
+
|
| 271 |
+
1. Implement analytics agent Python module
|
| 272 |
+
2. Create UI components according to specifications
|
| 273 |
+
3. Set up database tables and materialized views
|
| 274 |
+
4. Configure notification channels
|
| 275 |
+
5. Deploy monitoring infrastructure
|
| 276 |
+
6. Set up failover logging systems
|
| 277 |
+
7. Create integration tests
|
| 278 |
+
8. Document API with OpenAPI/Swagger specs
|
| 279 |
+
9. Create user documentation and tutorials
|
| 280 |
+
10. Set up monitoring dashboards and alerts
|
| 281 |
+
|
| 282 |
+
---
|
| 283 |
+
*Configuration file: [analytics_config.json](./analytics_config.json)*
|
| 284 |
+
*Last updated: 2025-11-05*
|