Expand description
API Analytics Module for Armature Framework
Provides comprehensive API usage tracking, rate limit insights, and error monitoring.
§Features
- Request Metrics: Track requests per endpoint, method, and status code
- Latency Tracking: P50, P90, P95, P99 latency percentiles
- Error Rates: Monitor error rates by endpoint and error type
- Rate Limit Insights: Track rate limit hits, rejections, and usage patterns
- Throughput Monitoring: Requests per second, minute, hour
- Real-time Dashboard: JSON endpoint for analytics data
§Quick Start
ⓘ
use armature_analytics::{Analytics, AnalyticsMiddleware};
use armature_core::Application;
let analytics = Analytics::new(AnalyticsConfig::default());
let app = Application::new(container, router)
.middleware(AnalyticsMiddleware::new(analytics.clone()));
// Access analytics endpoint
// GET /api/_analytics -> JSON dashboard data§Architecture
┌─────────────────────────────────────────────────────────────┐
│ Requests │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ AnalyticsMiddleware │
│ - Captures request/response metadata │
│ - Records timing, status, errors │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ MetricsCollector │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Requests │ │ Latency │ │ Errors │ │Rate Limit│ │
│ │ Counter │ │Histogram │ │ Tracker │ │ Insights │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Export Backends │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ JSON │ │Prometheus│ │ Custom │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘Structs§
- Analytics
- Main analytics instance
- Analytics
Config - Configuration for the analytics module
- Analytics
Config Builder - Builder for AnalyticsConfig
- Analytics
Context - Request context for tracking within handlers
- Analytics
Middleware - Middleware that automatically records analytics for all requests
- Analytics
Snapshot - Complete analytics snapshot for dashboard/export
- Client
Rate Limit Info - Rate limit info for a specific client
- Endpoint
Metrics - Per-endpoint metrics
- Error
Metrics - Error metrics summary
- Error
Record - Record of an error for analytics
- Error
Summary - Summary of a recent error
- Histogram
Value - Histogram metric value with buckets
- Insight
- An analytics insight
- Insight
Config - Configuration for insight detection
- Insight
Generator - Insight generator
- Latency
Metrics - Latency metrics with percentiles
- Metric
- Named metric with labels
- Metrics
Collector - Thread-safe metrics collector
- Rate
Limit Event - Record of a rate limit event
- Rate
Limit Metrics - Rate limit metrics
- Request
Metrics - Request metrics summary
- Request
Record - Record of a single request for analytics
- Throughput
Metrics - Throughput metrics
- Time
Series - Time series data
- Time
Series Point - Time series data point
- Tracked
Handler - Handler wrapper that automatically tracks analytics
Enums§
- Analytics
Error - Errors that can occur in the analytics module
- Insight
Type - Types of insights
- Metric
Type - Metric types
- Metric
Value - Metric value types
- Rate
Limit Event Type - Rate limit event types
- Severity
- Severity levels
Traits§
- Analytics
Ext - Extension trait for adding analytics to requests
- Duration
Ext - Duration formatting helpers
Functions§
- normalize_
path - Helper to normalize request paths for aggregation