This release transforms CpuGuard.NET into a full-featured resource management middleware with 10 new capabilities.
-
Memory Limiting (MemoryGuard)
- Monitor and limit memory usage with percentage or absolute byte thresholds
- Configurable response handling when limits are exceeded
-
Custom Response Handlers
- Define custom responses for throttled requests
- Support for JSON, HTML, or any content type
-
Event Callbacks
- Subscribe to
OnCpuLimitExceededandOnMemoryLimitExceededevents - Integrate with logging, alerting, and monitoring systems
- Subscribe to
-
Health Check Integration
- ASP.NET Core health check support with
AddCpuGuardHealthChecks() - Configurable degraded and unhealthy thresholds
- ASP.NET Core health check support with
-
OpenTelemetry Metrics
- Built-in metrics:
cpuguard_requests_throttled_total,cpuguard_cpu_usage_percent, etc. - Export to Prometheus, Grafana, and other observability platforms
- Built-in metrics:
-
Gradual Throttling
- Progressive request delays as resource usage increases
- Soft limit (start delaying) and hard limit (reject) thresholds
- Linear or exponential delay modes
-
Path Exclusions
- Exclude specific paths from all guards (e.g.,
/health,/metrics) - Support for custom exclusion predicates
- Exclude specific paths from all guards (e.g.,
-
Rate Limiting
- Per-client rate limiting with Fixed Window, Sliding Window, or Token Bucket algorithms
- CPU-aware rate limiting that reduces limits under high load
- Standard
X-RateLimit-*response headers
-
Real-time Dashboard
- Built-in HTML dashboard with live charts at
/cpuguard/dashboard - JSON stats API at
/cpuguard/statsand/cpuguard/stats/full - CPU/memory gauges, request statistics, and system info
- Built-in HTML dashboard with live charts at
-
Background Resource Monitoring
- Async CPU sampling via
ResourceMonitorService - Accurate resource tracking without blocking requests
- Async CPU sampling via
- Middleware now requires service registration via
AddCpuGuard(),AddMemoryGuard(), etc. - Legacy API (
UseCpuLimitMiddleware) still supported but deprecated
Microsoft.Extensions.Hosting.Abstractions(6.0.0)Microsoft.Extensions.Diagnostics.HealthChecks(6.0.0)OpenTelemetry.Api(1.7.0)System.Text.Json(8.0.5)
1. Introduced a middleware component to limit CPU usage across the entire ASP.NET Core application.
2. Configuration options:
1. cpuLimitPercentage: Sets the maximum allowed CPU usage as a percentage.
2. monitoringInterval: Defines the interval at which CPU usage is monitored.
3. When the CPU usage exceeds the specified limit, the middleware responds with HTTP 503 Service Unavailable, indicating that the server is overloaded.
1. Added middleware to limit CPU usage for specific requests.
2. Configuration options:
1. cpuLimitPercentage: Sets the maximum allowed CPU usage for the specific request.
2. monitoringInterval: Defines the interval at which CPU usage is monitored for the request.
3. When the CPU usage for a request exceeds the specified limit, the middleware responds with HTTP 503 Service Unavailable, indicating that the server is temporarily overloaded for that request.