Improved node statistics. Added overview for single nodes and replaced mockup values with api fetched values for nodes list

This commit is contained in:
2025-05-27 00:17:42 +02:00
parent de682ab7ae
commit f2771acb49
19 changed files with 853 additions and 223 deletions

View File

@@ -1,32 +0,0 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MoonlightServers.Daemon.Helpers;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Statistics;
namespace MoonlightServers.Daemon.Http.Controllers.Statistics;
// This controller hosts endpoints for the statistics for the daemon application itself
[Authorize]
[ApiController]
[Route("api/statistics/application")]
public class StatisticsApplicationController : Controller
{
private readonly OwnProcessHelper ProcessHelper;
public StatisticsApplicationController(OwnProcessHelper processHelper)
{
ProcessHelper = processHelper;
}
[HttpGet]
public async Task<StatisticsApplicationResponse> Get()
{
return new StatisticsApplicationResponse()
{
Uptime = ProcessHelper.GetUptime(),
MemoryUsage = ProcessHelper.GetMemoryUsage(),
CpuUsage = ProcessHelper.CpuUsage()
};
}
}

View File

@@ -0,0 +1,54 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MoonlightServers.Daemon.Helpers;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Statistics;
namespace MoonlightServers.Daemon.Http.Controllers.Statistics;
[Authorize]
[ApiController]
[Route("api/statistics")]
public class StatisticsController : Controller
{
private readonly HostSystemHelper HostSystemHelper;
public StatisticsController(HostSystemHelper hostSystemHelper)
{
HostSystemHelper = hostSystemHelper;
}
[HttpGet]
public async Task<StatisticsResponse> Get()
{
var response = new StatisticsResponse();
var cpuUsage = await HostSystemHelper.GetCpuUsage();
response.Cpu.Model = cpuUsage.Model;
response.Cpu.Usage = cpuUsage.OverallUsage;
response.Cpu.UsagePerCore = cpuUsage.PerCoreUsage;
var memoryUsage = await HostSystemHelper.GetMemoryUsage();
response.Memory.Available = memoryUsage.Available;
response.Memory.Cached = memoryUsage.Cached;
response.Memory.Free = memoryUsage.Free;
response.Memory.Total = memoryUsage.Total;
response.Memory.SwapTotal = memoryUsage.SwapTotal;
response.Memory.SwapFree = memoryUsage.SwapFree;
var diskDetails = await HostSystemHelper.GetDiskUsages();
response.Disks = diskDetails.Select(x => new StatisticsResponse.DiskData()
{
Device = x.Device,
MountPath = x.MountPath,
DiskFree = x.DiskFree,
DiskTotal = x.DiskTotal,
InodesFree = x.InodesFree,
InodesTotal = x.InodesTotal
}).ToArray();
return response;
}
}

View File

@@ -1,30 +0,0 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MoonlightServers.Daemon.Helpers;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Statistics;
namespace MoonlightServers.Daemon.Http.Controllers.Statistics;
// This controller hosts endpoints for the statistics for host system the daemon runs on
[Authorize]
[ApiController]
[Route("api/statistics/host")]
public class StatisticsHostController : Controller
{
private readonly HostSystemHelper HostSystemHelper;
public StatisticsHostController(HostSystemHelper hostSystemHelper)
{
HostSystemHelper = hostSystemHelper;
}
[HttpGet]
public async Task<StatisticsHostResponse> Get()
{
return new()
{
OperatingSystem = HostSystemHelper.GetOsName()
};
}
}