Merge pull request #151 from Moonlight-Panel/AddUptimeCounter
Added uptime service
This commit is contained in:
@@ -17,6 +17,18 @@ public static class Formatter
|
||||
return $"{t.Hours}h {t.Minutes}m {t.Seconds}s";
|
||||
}
|
||||
}
|
||||
|
||||
public static string FormatUptime(TimeSpan t)
|
||||
{
|
||||
if (t.Days > 0)
|
||||
{
|
||||
return $"{t.Days}d {t.Hours}h {t.Minutes}m {t.Seconds}s";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{t.Hours}h {t.Minutes}m {t.Seconds}s";
|
||||
}
|
||||
}
|
||||
|
||||
private static double Round(this double d, int decimals)
|
||||
{
|
||||
|
||||
11
Moonlight/App/Services/Background/UptimeService.cs
Normal file
11
Moonlight/App/Services/Background/UptimeService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Moonlight.App.Services.Background;
|
||||
|
||||
public class UptimeService
|
||||
{
|
||||
public DateTime StartTimestamp { get; private set; }
|
||||
|
||||
public UptimeService()
|
||||
{
|
||||
StartTimestamp = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,7 @@ namespace Moonlight
|
||||
builder.Services.AddSingleton<StatisticsCaptureService>();
|
||||
builder.Services.AddSingleton<DiscordNotificationService>();
|
||||
builder.Services.AddSingleton<CleanupService>();
|
||||
builder.Services.AddSingleton<UptimeService>();
|
||||
|
||||
// Third party services
|
||||
builder.Services.AddBlazorTable();
|
||||
@@ -202,6 +203,7 @@ namespace Moonlight
|
||||
_ = app.Services.GetRequiredService<DiscordBotService>();
|
||||
_ = app.Services.GetRequiredService<StatisticsCaptureService>();
|
||||
_ = app.Services.GetRequiredService<DiscordNotificationService>();
|
||||
_ = app.Services.GetRequiredService<UptimeService>();
|
||||
|
||||
// Discord bot service
|
||||
//var discordBotService = app.Services.GetRequiredService<DiscordBotService>();
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
@using Moonlight.Shared.Components.Navigations
|
||||
@using Moonlight.App.Helpers
|
||||
@using Moonlight.App.Services.Background
|
||||
|
||||
@inject HostSystemHelper HostSystemHelper
|
||||
@inject UptimeService UptimeService
|
||||
|
||||
<OnlyAdmin>
|
||||
<AdminSystemNavigation Index="0"/>
|
||||
@@ -70,5 +72,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl-6 my-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">
|
||||
<TL>Uptime</TL>
|
||||
</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<span class="fs-5">
|
||||
<TL>Moonlight is since</TL>
|
||||
<span class="text-primary">
|
||||
@(Formatter.FormatUptime(DateTime.UtcNow - UptimeService.StartTimestamp))
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</OnlyAdmin>
|
||||
Reference in New Issue
Block a user