Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal

- name: Pack (verify)
run: dotnet pack CpuGuard.NET/CpuGuard.NET.csproj --configuration Release --no-build --output ./artifacts

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: ./artifacts/*.nupkg
retention-days: 7
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release to NuGet

on:
push:
tags:
- 'v*.*.*'

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal

- name: Pack
run: dotnet pack CpuGuard.NET/CpuGuard.NET.csproj --configuration Release --no-build -p:PackageVersion=${{ steps.get_version.outputs.VERSION }} --output ./artifacts

- name: Push to NuGet
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: ./artifacts/*.nupkg
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 9 additions & 13 deletions CpuGuard.NET/CpuGuard.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<Version>2.0.0</Version>
<PackageVersion>$(Version)</PackageVersion>
<Authors>Khaled Md Tuhidul Hossain</Authors>
<Company>EncryptedTouhid</Company>
<Description>Comprehensive resource management middleware for ASP.NET Core applications. Features include CPU and memory limiting, gradual throttling, rate limiting, health checks, OpenTelemetry metrics, and a real-time dashboard.</Description>
<PackageTags>cpu limit middleware aspnetcore throttling performance memory rate-limiting health-check opentelemetry dashboard</PackageTags>
<RepositoryUrl>https://github.com/encryptedtouhid/CpuGuard.NET</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/encryptedtouhid/CpuGuard.NET</PackageProjectUrl>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,19 +35,9 @@
<EmbeddedResource Include="Dashboard\dashboard.html" />
</ItemGroup>



<ItemGroup>
<None Update="LICENSE">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Update="README.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\LICENSE.md" Pack="true" PackagePath="\" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
70 changes: 68 additions & 2 deletions RELEASE-NOTE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
# Release Notes for CpuGuard.NET
## Version 1.0.1
# Release Notes for CpuGuard.NET

## Version 2.0.0

### Major Release - Comprehensive Resource Management

This release transforms CpuGuard.NET into a full-featured resource management middleware with 10 new capabilities.

#### New Features

1. **Memory Limiting (MemoryGuard)**
- Monitor and limit memory usage with percentage or absolute byte thresholds
- Configurable response handling when limits are exceeded

2. **Custom Response Handlers**
- Define custom responses for throttled requests
- Support for JSON, HTML, or any content type

3. **Event Callbacks**
- Subscribe to `OnCpuLimitExceeded` and `OnMemoryLimitExceeded` events
- Integrate with logging, alerting, and monitoring systems

4. **Health Check Integration**
- ASP.NET Core health check support with `AddCpuGuardHealthChecks()`
- Configurable degraded and unhealthy thresholds

5. **OpenTelemetry Metrics**
- Built-in metrics: `cpuguard_requests_throttled_total`, `cpuguard_cpu_usage_percent`, etc.
- Export to Prometheus, Grafana, and other observability platforms

6. **Gradual Throttling**
- Progressive request delays as resource usage increases
- Soft limit (start delaying) and hard limit (reject) thresholds
- Linear or exponential delay modes

7. **Path Exclusions**
- Exclude specific paths from all guards (e.g., `/health`, `/metrics`)
- Support for custom exclusion predicates

8. **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

9. **Real-time Dashboard**
- Built-in HTML dashboard with live charts at `/cpuguard/dashboard`
- JSON stats API at `/cpuguard/stats` and `/cpuguard/stats/full`
- CPU/memory gauges, request statistics, and system info

10. **Background Resource Monitoring**
- Async CPU sampling via `ResourceMonitorService`
- Accurate resource tracking without blocking requests

#### Breaking Changes

- Middleware now requires service registration via `AddCpuGuard()`, `AddMemoryGuard()`, etc.
- Legacy API (`UseCpuLimitMiddleware`) still supported but deprecated

#### New Dependencies

- `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)

---

## Version 1.0.1
#### Whole Application CPU Limit:

1. Introduced a middleware component to limit CPU usage across the entire ASP.NET Core application.
Expand Down
Loading