Re-organised statistic endpoints and services/helpers
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonlightServers.Daemon.Helpers;
|
||||
using MoonlightServers.DaemonShared.Http.Responses.Statistics;
|
||||
|
||||
namespace MoonlightServers.Daemon.Http.Controllers.Statistics;
|
||||
|
||||
// This controller hosts endpoints for the statistics for the daemon application itself
|
||||
|
||||
[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()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonlightServers.Daemon.Services;
|
||||
using MoonlightServers.DaemonShared.Http.Responses.Statistics;
|
||||
|
||||
namespace MoonlightServers.Daemon.Http.Controllers.Statistics;
|
||||
|
||||
// This controller hosts endpoints for the statistics for the docker environment
|
||||
|
||||
[ApiController]
|
||||
[Route("api/statistics/docker")]
|
||||
public class StatisticsDockerController : Controller
|
||||
{
|
||||
private readonly DockerInfoService DockerInfoService;
|
||||
|
||||
public StatisticsDockerController(DockerInfoService dockerInfoService)
|
||||
{
|
||||
DockerInfoService = dockerInfoService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<StatisticsDockerResponse> Get()
|
||||
{
|
||||
var usage = await DockerInfoService.GetDataUsage();
|
||||
|
||||
return new StatisticsDockerResponse
|
||||
{
|
||||
Version = await DockerInfoService.GetDockerVersion(),
|
||||
ContainersReclaimable = usage.Containers.Reclaimable,
|
||||
ContainersUsed = usage.Containers.Used,
|
||||
BuildCacheReclaimable = usage.BuildCache.Reclaimable,
|
||||
BuildCacheUsed = usage.BuildCache.Used,
|
||||
ImagesUsed = usage.Images.Used,
|
||||
ImagesReclaimable = usage.Images.Reclaimable
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonlightServers.Daemon.Helpers;
|
||||
using MoonlightServers.DaemonShared.Http.Responses.Statistics;
|
||||
|
||||
namespace MoonlightServers.Daemon.Http.Controllers.Statistics;
|
||||
|
||||
// This controller hosts endpoints for the statistics for host system the daemon runs on
|
||||
|
||||
[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()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonlightServers.Daemon.Services;
|
||||
using MoonlightServers.DaemonShared.Http.Responses.Sys;
|
||||
|
||||
namespace MoonlightServers.Daemon.Http.Controllers.Sys;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/system/dataUsage")]
|
||||
public class SystemDataUsageController : Controller
|
||||
{
|
||||
private readonly DockerInfoService DockerInfoService;
|
||||
|
||||
public SystemDataUsageController(DockerInfoService dockerInfoService)
|
||||
{
|
||||
DockerInfoService = dockerInfoService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<SystemDataUsageResponse> Get()
|
||||
{
|
||||
var report = await DockerInfoService.GetDataUsage();
|
||||
|
||||
return new SystemDataUsageResponse()
|
||||
{
|
||||
ImagesReclaimable = report.Images.Reclaimable,
|
||||
ImagesUsed = report.Images.Used,
|
||||
ContainersReclaimable = report.Containers.Reclaimable,
|
||||
ContainersUsed = report.Containers.Used,
|
||||
BuildCacheReclaimable = report.BuildCache.Reclaimable,
|
||||
BuildCacheUsed = report.BuildCache.Used
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonlightServers.Daemon.Services;
|
||||
using MoonlightServers.DaemonShared.Http.Responses.Sys;
|
||||
|
||||
namespace MoonlightServers.Daemon.Http.Controllers.Sys;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/system/info")]
|
||||
public class SystemInfoController : Controller
|
||||
{
|
||||
private readonly SystemInfoService SystemInfoService;
|
||||
private readonly DockerInfoService DockerInfoService;
|
||||
|
||||
public SystemInfoController(SystemInfoService systemInfoService, DockerInfoService dockerInfoService)
|
||||
{
|
||||
SystemInfoService = systemInfoService;
|
||||
DockerInfoService = dockerInfoService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<SystemInfoResponse> GetInfo()
|
||||
{
|
||||
return new SystemInfoResponse()
|
||||
{
|
||||
Uptime = await SystemInfoService.GetUptime(),
|
||||
Version = "2.1.0",
|
||||
CpuUsage = await SystemInfoService.GetCpuUsage(),
|
||||
DockerVersion = await DockerInfoService.GetDockerVersion(),
|
||||
MemoryUsage = await SystemInfoService.GetMemoryUsage(),
|
||||
OsName = await SystemInfoService.GetOsName()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user