36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using MD.PersianDateTime.Standard;
|
|
|
|
namespace Netina.Api.Controllers;
|
|
|
|
public class HealthController : ICarterModule
|
|
{
|
|
public void AddRoutes(IEndpointRouteBuilder app)
|
|
{
|
|
var group = app.NewVersionedApi("Health")
|
|
.MapGroup("health");
|
|
group.MapGet("", GetHealth)
|
|
.WithDisplayName("GetHealth")
|
|
.HasApiVersion(1.0);
|
|
group.MapGet("/error/test", () => { throw new Exception("Error test message");})
|
|
.WithDisplayName("GetHealth")
|
|
.HasApiVersion(1.0);
|
|
}
|
|
|
|
public async Task<IResult> GetHealth([FromServices]ISiteMapService siteMapService)
|
|
{
|
|
//await siteMapService.CreateSiteMapAsync();
|
|
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
|
|
var check = new HealthCheck
|
|
{
|
|
Health = true,
|
|
Version = version ?? string.Empty,
|
|
StartAt = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString("F"),
|
|
StartAtPersian = new PersianDateTime(System.Diagnostics.Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
|
|
MachineName = Environment.MachineName
|
|
};
|
|
var process = Process.GetCurrentProcess();
|
|
check.TotalMemory = process.PrivateMemorySize64.ToString();
|
|
|
|
return TypedResults.Ok(check);
|
|
}
|
|
} |