From f12900081accf64f84b33ac3c80b0f2278ba9ba6 Mon Sep 17 00:00:00 2001 From: Ayymoss Date: Wed, 4 Sep 2024 13:55:20 +0100 Subject: [PATCH] Add instance uptime to API info response This update includes the instance uptime in the API info response. --- WebfrontCore/Controllers/API/Dtos/InfoResponse.cs | 1 + WebfrontCore/Controllers/API/Info.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/WebfrontCore/Controllers/API/Dtos/InfoResponse.cs b/WebfrontCore/Controllers/API/Dtos/InfoResponse.cs index 4909b0b5a..626600c31 100644 --- a/WebfrontCore/Controllers/API/Dtos/InfoResponse.cs +++ b/WebfrontCore/Controllers/API/Dtos/InfoResponse.cs @@ -10,6 +10,7 @@ public class InfoResponse public MetricSnapshot TotalRecentClients { get; set; } public MetricSnapshot MaxConcurrentClients { get; set; } + public TimeSpan Uptime { get; set; } } public class MetricSnapshot diff --git a/WebfrontCore/Controllers/API/Info.cs b/WebfrontCore/Controllers/API/Info.cs index 385f511c1..da0707950 100644 --- a/WebfrontCore/Controllers/API/Info.cs +++ b/WebfrontCore/Controllers/API/Info.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -30,6 +31,7 @@ public async Task Get(int period = 24, Reference.Game? game = nul var (totalClients, totalRecentClients) = await _serverDataViewer.ClientCountsAsync(duration, game, token); var (maxConcurrent, maxConcurrentTime) = await _serverDataViewer.MaxConcurrentClientsAsync(overPeriod: duration, token: token); + var uptime = DateTime.Now - Process.GetCurrentProcess().StartTime; var response = new InfoResponse { TotalTrackedClients = totalClients, @@ -46,7 +48,8 @@ public async Task Get(int period = 24, Reference.Game? game = nul Value = totalRecentClients, EndAt = DateTime.UtcNow, StartAt = DateTime.UtcNow - duration - } + }, + Uptime = uptime, }; return Json(response);