First commit

This commit is contained in:
2026-06-28 01:38:39 +03:00
commit b53c690457
16 changed files with 358 additions and 0 deletions
@@ -0,0 +1,3 @@
namespace MonitorAgent.API.Contracts;
public record class LoadAverageResponse(decimal[] LoadAverage);
@@ -0,0 +1,10 @@
namespace MonitorAgent.API.Contracts;
public record class MemoryResponse
(
int MemTotal,
int MemFree,
int MemAvailable,
int SwapTotal,
int SwapFree
);
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Mvc;
using MonitorAgent.API.Contracts;
using MonitorAgent.Core.Abstraction;
namespace MonitorAgent.API.Controllers;
[ApiController]
[Route("[controller]")]
public class MonitorController(IMonitorService monitorService) : ControllerBase
{
[HttpGet("uptime")]
public async Task<ActionResult<decimal>> GetUptimeAsync(CancellationToken cancellationToken = default)
{
var uptime = await monitorService.GetUptimeAsync(cancellationToken);
return Ok(uptime);
}
[HttpGet("memory")]
public async Task<ActionResult<MemoryResponse>> GetMemoryAsync(CancellationToken cancellationToken = default)
{
var memInfo = await monitorService.GetMemoryInfoAsync(cancellationToken);
var response = new MemoryResponse(
memInfo.MemTotal,
memInfo.MemFree,
memInfo.MemAvailable,
memInfo.SwapTotal,
memInfo.SwapFree
);
return Ok(response);
}
[HttpGet("loadavg")]
public async Task<ActionResult<LoadAverageResponse>> GetActionResultAsync(CancellationToken cancellationToken = default)
{
var response = new LoadAverageResponse(await monitorService.GetLoadAverageAsync(cancellationToken));
return Ok(response);
}
}
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MonitorAgent.Core\MonitorAgent.Core.csproj" />
<ProjectReference Include="..\MonitorAgent.Application\MonitorAgent.Application.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,6 @@
@MonitorAgent.API_HostAddress = http://localhost:5170
GET {{MonitorAgent.API_HostAddress}}/weatherforecast/
Accept: application/json
###
@@ -0,0 +1,33 @@
using MonitorAgent.Core.Abstraction;
using MonitorAgent.Application.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IMonitorService, MonitorService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.UseSwagger().UseSwaggerUI();
app.Run();
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5170",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7032;http://localhost:5170",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}