From 1c0fab71bb28401468c46e3a2903d902e5935470 Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Tue, 26 Aug 2025 18:54:17 +0200 Subject: [PATCH 01/16] new Dashboard --- Watcher/Controllers/HomeController.cs | 37 +++-- Watcher/Models/HealthStatus.cs | 16 ++ Watcher/Program.cs | 11 +- Watcher/ViewModels/DashboardViewModel.cs | 7 + Watcher/Views/Home/Index.cshtml | 19 --- Watcher/Views/Home/_DashboardStats.cshtml | 179 ++++++++++++++++++++-- Watcher/Views/Shared/_Layout.cshtml | 4 +- 7 files changed, 220 insertions(+), 53 deletions(-) create mode 100644 Watcher/Models/HealthStatus.cs diff --git a/Watcher/Controllers/HomeController.cs b/Watcher/Controllers/HomeController.cs index f043b7c..2032eb2 100644 --- a/Watcher/Controllers/HomeController.cs +++ b/Watcher/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; // Local Namespaces using Watcher.Data; +using Watcher.Models; using Watcher.ViewModels; namespace Watcher.Controllers @@ -41,7 +42,17 @@ namespace Watcher.Controllers OfflineServers = await _context.Servers.CountAsync(s => !s.IsOnline), RunningContainers = await _context.Containers.CountAsync(c => c.IsRunning), FailedContainers = await _context.Containers.CountAsync(c => !c.IsRunning), - LastLogin = user?.LastLogin ?? DateTime.MinValue + LastLogin = user?.LastLogin ?? DateTime.MinValue, + Servers = await _context.Servers + .OrderBy(s => s.Name) + .ToListAsync(), + RecentEvents = await _context.LogEvents + .OrderByDescending(e => e.Timestamp) + .Take(20) + .ToListAsync(), + Containers = await _context.Containers + .OrderBy(s => s.Name) + .ToListAsync() }; return View(viewModel); @@ -49,7 +60,7 @@ namespace Watcher.Controllers // Funktion für /Views/Home/Index.cshtml um das DashboardStats-Partial neu zu laden. // Die Funktion wird nicht direkt aufgerufen, sondern nur der /Home/DashboardStats Endpoint angefragt. - public IActionResult DashboardStats() + public async Task DashboardStats() { var servers = _context.Servers.ToList(); var containers = _context.Containers.ToList(); @@ -58,14 +69,20 @@ namespace Watcher.Controllers var model = new DashboardViewModel { - ActiveServers = servers.Count(s => (now - s.LastSeen).TotalSeconds <= 120), - OfflineServers = servers.Count(s => (now - s.LastSeen).TotalSeconds > 120), - - //TODO: anwendbar, wenn Container implementiert wurden. - //RunningContainers = containers.Count(c => (now - c.LastSeen).TotalSeconds <= 120), - //FailedContainers = containers.Count(c => (now - c.LastSeen).TotalSeconds > 120), - - LastLogin = DateTime.Now + ActiveServers = await _context.Servers.CountAsync(s => s.IsOnline), + OfflineServers = await _context.Servers.CountAsync(s => !s.IsOnline), + RunningContainers = await _context.Containers.CountAsync(c => c.IsRunning), + FailedContainers = await _context.Containers.CountAsync(c => !c.IsRunning), + Servers = await _context.Servers + .OrderBy(s => s.Name) + .ToListAsync(), + RecentEvents = await _context.LogEvents + .OrderByDescending(e => e.Timestamp) + .Take(20) + .ToListAsync(), + Containers = await _context.Containers + .OrderBy(s => s.Name) + .ToListAsync() }; return PartialView("_DashboardStats", model); diff --git a/Watcher/Models/HealthStatus.cs b/Watcher/Models/HealthStatus.cs new file mode 100644 index 0000000..9e0012b --- /dev/null +++ b/Watcher/Models/HealthStatus.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Watcher.Models +{ + public class HealthStatus + { + public DateTime Timestamp { get; set; } + + public bool NetworkOk { get; set; } + public bool DatabaseOk { get; set; } + public List Issues { get; set; } = new List(); + // Optional weitere Checks + public bool ApiOk { get; set; } + public bool DiskOk { get; set; } + } +} diff --git a/Watcher/Program.cs b/Watcher/Program.cs index 0c4e404..c20d108 100644 --- a/Watcher/Program.cs +++ b/Watcher/Program.cs @@ -1,14 +1,12 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Sqlite; -using Microsoft.IdentityModel.Tokens; using Serilog; using Watcher.Data; using Watcher.Models; +//using Watcher.Services; +//using Watcher.Workers; var builder = WebApplication.CreateBuilder(args); @@ -32,7 +30,6 @@ builder.Host.UseSerilog(); // Add services to the container. builder.Services.AddControllersWithViews(); - // HttpContentAccessor builder.Services.AddHttpContextAccessor(); @@ -112,7 +109,11 @@ builder.Services.AddAuthentication() var db = ctx.HttpContext.RequestServices.GetRequiredService(); var principal = ctx.Principal; +#pragma warning disable CS8602 // Dereference of a possibly null reference. + var pocketId = principal.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value; +#pragma warning restore CS8602 // Dereference of a possibly null reference. + var preferredUsername = principal.FindFirst("preferred_username")?.Value; var email = principal.FindFirst("email")?.Value; diff --git a/Watcher/ViewModels/DashboardViewModel.cs b/Watcher/ViewModels/DashboardViewModel.cs index 02bf40f..624c9bd 100644 --- a/Watcher/ViewModels/DashboardViewModel.cs +++ b/Watcher/ViewModels/DashboardViewModel.cs @@ -1,3 +1,5 @@ +using Watcher.Models; + namespace Watcher.ViewModels { public class DashboardViewModel @@ -7,5 +9,10 @@ namespace Watcher.ViewModels public int RunningContainers { get; set; } public int FailedContainers { get; set; } public DateTime LastLogin { get; set; } + + public List Servers { get; set; } = new(); + public List RecentEvents { get; set; } = new(); + public List Containers { get; set; } = new(); + } } diff --git a/Watcher/Views/Home/Index.cshtml b/Watcher/Views/Home/Index.cshtml index 6b61e39..08bdad0 100644 --- a/Watcher/Views/Home/Index.cshtml +++ b/Watcher/Views/Home/Index.cshtml @@ -11,25 +11,6 @@ @await Html.PartialAsync("_DashboardStats", Model) -
- -
-
-

- Systeminfo -

-

- - Benutzer: @User.FindFirst("preferred_username")?.Value -

-

- - Letzter Login: @Model.LastLogin.ToString("g") -

-
-
-
- @section Scripts { +} diff --git a/Watcher/Views/Shared/_Layout.cshtml b/Watcher/Views/Shared/_Layout.cshtml index fbbcff3..aedb283 100644 --- a/Watcher/Views/Shared/_Layout.cshtml +++ b/Watcher/Views/Shared/_Layout.cshtml @@ -71,10 +71,10 @@ Dashboard -
- + +
+

test

- -
-
Server Online
+
Server Online

@Model.ActiveServers

@@ -27,7 +26,7 @@
-
Server Offline
+
Server Offline

@Model.OfflineServers

@@ -36,7 +35,7 @@
-
Services Running
+
Services Running

@Model.RunningContainers

@@ -45,7 +44,7 @@
-
Service Warnungen
+
Service Warnungen

@Model.FailedContainers

@@ -76,13 +75,6 @@
-
- API - Langsam -
-
-
-
@@ -108,7 +100,7 @@
-
+

Services

    @foreach (var service in Model.Containers) @@ -126,7 +118,7 @@
    -
    +

    Server

      @foreach (var server in Model.Servers) @@ -148,23 +140,6 @@
    -
    -
-@section Scripts { - -} + + \ No newline at end of file diff --git a/Watcher/Views/Server/AddServer.cshtml b/Watcher/Views/Server/AddServer.cshtml index 0b35625..fbecce7 100644 --- a/Watcher/Views/Server/AddServer.cshtml +++ b/Watcher/Views/Server/AddServer.cshtml @@ -3,6 +3,10 @@ ViewData["Title"] = "Neuen Server hinzufügen"; } + + + +

diff --git a/Watcher/Views/Server/Details.cshtml b/Watcher/Views/Server/Details.cshtml index 3b05245..8e91c98 100644 --- a/Watcher/Views/Server/Details.cshtml +++ b/Watcher/Views/Server/Details.cshtml @@ -16,57 +16,75 @@ @(Model.IsOnline ? "Online" : "Offline")

-
-
-
ID
-
@Model.Id
-
IP-Adresse
-
@Model.IPAddress
- -
Typ
-
@Model.Type
- -
Erstellt am
-
@Model.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")
- -
Zuletzt gesehen
-
@Model.LastSeen.ToLocalTime().ToString("dd.MM.yyyy HH:mm")
-
-
- -
-
CPU Last
-
- -
-
+
+
+
ID
+
@Model.Id
-
-
RAM Last
-
- -
-
+
IP-Adresse
+
@Model.IPAddress
-
-
GPU Last
-
- -
+
Typ
+
@Model.Type
+ +
Erstellt am
+
@Model.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")
+ +
Zuletzt gesehen
+
@Model.LastSeen.ToLocalTime().ToString("dd.MM.yyyy HH:mm")
+
+ +
+ +
+
CPU Last
+
+ +
+
+ + +
RAM Last
+
+ +
+ + +
+
GPU Last
+
+ +
+ diff --git a/Watcher/Views/Server/_ServerCard.cshtml b/Watcher/Views/Server/_ServerCard.cshtml index efc6f42..5d7a087 100644 --- a/Watcher/Views/Server/_ServerCard.cshtml +++ b/Watcher/Views/Server/_ServerCard.cshtml @@ -8,34 +8,24 @@
-
- (#@s.Id) @s.Name +
+ (#@s.Id) @s.Name
+ +
+
IP: @s.IPAddress
+
Typ: @s.Type
+ +
+ + @(s.IsOnline ? "bg-success text-light" : "bg-danger text-light")"> @(s.IsOnline ? "Online" : "Offline")
-
-
-
IP: @s.IPAddress
-
Typ: @s.Type
-
Erstellt: - @s.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")
-
Last-Seen: - @s.LastSeen.ToLocalTime().ToString("dd.MM.yyyy HH:mm")
-
CPU: @(s.CpuType ?? "not found")
-
CPU-Kerne: @s.CpuCores
-
GPU: @(s.GpuType ?? "not found") -
-
RAM: @(s.RamSize)
-
Disk Space: ...
-
-
- -
+
Bearbeiten @@ -46,11 +36,6 @@ Metrics - - Container - -
+
+ +
-
- - Bearbeiten - - - - Metrics - - -
- -
- -
diff --git a/Watcher/Views/Server/overview.cshtml b/Watcher/Views/Server/overview.cshtml index 29f4748..19bfe2e 100644 --- a/Watcher/Views/Server/overview.cshtml +++ b/Watcher/Views/Server/overview.cshtml @@ -2,24 +2,32 @@ @{ ViewData["Title"] = "Serverübersicht"; } + + +
-

- Serverübersicht + +

+ Serverübersicht

-
- -
+ + + + +
+ +
@await Html.PartialAsync("_ServerCard", Model.Servers)
+ + @section Scripts { @@ -106,7 +94,6 @@ datasets: [{ label: 'CPU Last (%)', data: [], - borderColor: 'rgb(255, 99, 132)', backgroundColor: 'rgba(255, 99, 132, 0.2)', fill: true, tension: 0.3, @@ -127,7 +114,7 @@ }, x: { title: { - display: true, + display: false, text: 'Zeit' } } @@ -142,7 +129,6 @@ datasets: [{ label: 'RAM Last (%)', data: [], - borderColor: 'rgb(255, 99, 132)', backgroundColor: 'rgba(255, 99, 132, 0.2)', fill: true, tension: 0.3, @@ -158,12 +144,12 @@ max: 100, title: { display: true, - text: 'Prozent' + text: 'Auslastung in %' } }, x: { title: { - display: true, + display: false, text: 'Zeit' } } @@ -178,7 +164,6 @@ datasets: [{ label: 'GPU Last (%)', data: [], - borderColor: 'rgb(255, 99, 132)', backgroundColor: 'rgba(255, 99, 132, 0.2)', fill: true, tension: 0.3, @@ -194,12 +179,12 @@ max: 100, title: { display: true, - text: 'Prozent' + text: 'Auslastung in %' } }, x: { title: { - display: true, + display: false, text: 'Zeit' } } diff --git a/Watcher/Views/Server/EditServer.cshtml b/Watcher/Views/Server/EditServer.cshtml index 23b4a5d..5587b6b 100644 --- a/Watcher/Views/Server/EditServer.cshtml +++ b/Watcher/Views/Server/EditServer.cshtml @@ -4,31 +4,36 @@ ViewData["Title"] = "Server bearbeiten"; } + + + + +

Server bearbeiten

@Html.AntiForgeryToken() -
+

Allgemeine Informationen

- +
- +
- + -
-
- - -
-
- - -
- - -
- } - else - { -
- Benutzerdaten können nur für lokal angemeldete Nutzer geändert werden. -
- } - - +

Systemeinformationen


-
Watcher Version: v0.1.0
+
Watcher Version: @ServerVersion

diff --git a/Watcher/Views/User/Info.cshtml b/Watcher/Views/User/Info.cshtml index 7490db9..574bd78 100644 --- a/Watcher/Views/User/Info.cshtml +++ b/Watcher/Views/User/Info.cshtml @@ -89,6 +89,29 @@ + + +
+

Benutzerdaten ändern

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+