ASP.NET Core API for collecting Linux system metrics and storing alerts in PostgreSQL.
This project focuses on a small and readable monitoring API for Linux environments. Instead of introducing layers and abstractions too early, it favors a straightforward implementation that is easy to inspect, explain, and extend.
The simplicity is intentional. For a project of this size, keeping the code direct makes the monitoring flow easier to validate, debug, and evolve.
- CPU, RAM, disk, and active process monitoring
- metric persistence with Entity Framework Core and PostgreSQL
- automatic alert creation based on thresholds
- endpoints for metric history and alerts
- Swagger enabled in development
- .NET 8
- ASP.NET Core Minimal API
- Entity Framework Core
- PostgreSQL
- simple code over premature abstraction
- explicit request flow instead of hidden framework magic
- direct access to Linux system data through
/procandDriveInfo - persistence kept close to the API flow for clarity
- thresholds defined in code to keep the alerting behavior easy to understand
When GET /api/metric is called, the API performs the full monitoring cycle in one request:
MonitorServicereads Linux system information.- A
Metricentity is created with CPU, RAM, disk, and process data. - The metric is stored in PostgreSQL.
- Threshold rules are evaluated.
- If a threshold is exceeded, one or more
Alertadorrecords are created. - The metric is returned in the HTTP response.
The additional endpoints expose stored data:
GET /api/metric/historyreturns saved metric history.GET /api/alertsreturns stored alerts ordered by creation date.
Program.cs: application startup, dependency injection, and HTTP endpointsServices/MonitorService.cs: Linux metric collection logicModels/: entity classes for metrics, servers, and alertsData/AppDbContext.cs: Entity Framework database contextMigrations/: versioned database schema history
Even though the codebase is intentionally simple, a few practical issues appeared while building the project:
- the original MVC controller route was not being exposed at runtime
- Swagger initially showed no usable endpoint paths
- the alert flow needed schema cleanup so the migration history stayed coherent
For a short troubleshooting note, see docs/WHY_IT_FAILED.md.
The project no longer stores the connection string in source code. Configure it with user secrets:
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Host=localhost;Database=LinuxMonitor;Username=postgres;Password=TU_PASSWORD"You can also use an environment variable:
export ConnectionStrings__DefaultConnection="Host=localhost;Database=LinuxMonitor;Username=postgres;Password=TU_PASSWORD"git clone https://github.com/Alfred-DMB/C-Server-Monitor.git
cd C-Server-Monitor
dotnet restore
dotnet ef database update
dotnet run --launch-profile httpGET /api/metricGET /api/metric/historyGET /api/alerts
- Swagger is available at
/swaggerwhenASPNETCORE_ENVIRONMENT=Development. - Quick project commands are listed in
COMANDOS.md. - The GitHub repository is named
C-Server-Monitor, while the internal .NET project name is stillServerMonitor. - The codebase is intentionally small and direct; the goal is clarity first, then incremental improvement if the project grows.