Created
July 10, 2025 10:59
-
-
Save nejdetkadir/7e9bbcb233293fbed8e528bf62d5cbf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : AbpController | |
{ | |
private static readonly DateTime StartupTime = DateTime.UtcNow; | |
private static readonly Stopwatch Stopwatch = Stopwatch.StartNew(); | |
public ActionResult Index() | |
{ | |
return Redirect("~/swagger"); | |
} | |
[HttpGet("health")] | |
public ActionResult Health() | |
{ | |
var currentTime = DateTime.UtcNow; | |
var uptime = currentTime - StartupTime; | |
var response = new | |
{ | |
startupTime = StartupTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), | |
currentTime = currentTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), | |
uptimeMs = (long)uptime.TotalMilliseconds, | |
uptimeFormatted = FormatUptime(uptime), | |
uptimePreciseMs = Stopwatch.ElapsedMilliseconds, | |
status = "UP", | |
}; | |
return Ok(response); | |
} | |
private static string FormatUptime(TimeSpan uptime) | |
{ | |
if (uptime.Days > 0) | |
{ | |
return $"{uptime.Days}d {uptime.Hours}h {uptime.Minutes}m {uptime.Seconds}s"; | |
} | |
else if (uptime.Hours > 0) | |
{ | |
return $"{uptime.Hours}h {uptime.Minutes}m {uptime.Seconds}s"; | |
} | |
else if (uptime.Minutes > 0) | |
{ | |
return $"{uptime.Minutes}m {uptime.Seconds}s"; | |
} | |
else | |
{ | |
return $"{uptime.Seconds}s"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment