15 Commits

Author SHA1 Message Date
45c46e0f63 Merge branch 'staging' of https://git.triggermeelmo.com/Watcher/watcher into staging
Some checks failed
Gitea CI/CD / dotnet-build-and-test (push) Failing after 43s
Gitea CI/CD / Set Tag Name (push) Has been skipped
Gitea CI/CD / docker-build-and-push (push) Has been skipped
Gitea CI/CD / Create Tag (push) Has been skipped
2025-12-03 15:02:55 +01:00
4903187a37 ka 2025-12-03 15:02:12 +01:00
96c481c4c1 Added Debug Notes
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 47s
Gitea CI/CD / Set Tag Name (push) Successful in 6s
Gitea CI/CD / docker-build-and-push (push) Successful in 6m40s
Gitea CI/CD / Create Tag (push) Successful in 6s
2025-11-23 10:39:03 +01:00
6eec58b8e7 Off-By-One Error in Datebank Migration behoben 2025-11-19 14:25:22 +01:00
a7ca1214f3 Rootless User konfigurierbar + Doku 2025-11-19 14:21:22 +01:00
1aab81a7fc Bug bei Passwortänderung behoben 2025-11-19 14:01:54 +01:00
f8961320c5 DB startet Server bei ID 0
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 55s
Gitea CI/CD / Set Tag Name (push) Successful in 6s
Gitea CI/CD / docker-build-and-push (push) Successful in 7m42s
Gitea CI/CD / Create Tag (push) Successful in 7s
2025-11-17 15:37:28 +01:00
23cac83061 Server-Übersicht Metric
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 45s
Gitea CI/CD / Set Tag Name (push) Successful in 5s
Gitea CI/CD / docker-build-and-push (push) Successful in 5m55s
Gitea CI/CD / Create Tag (push) Successful in 5s
2025-11-17 00:47:51 +01:00
2576604a4a CodeStyle, Compose verbesserungen, Docker Healthcheck 2025-11-17 00:44:10 +01:00
8a753ca9ba Refresh Rate anpassbar, Containerübersicht wird nicht mehr überschrieben 2025-11-16 23:53:58 +01:00
6429489f80 Readme aktualisiert 2025-11-16 23:37:12 +01:00
ef51e95483 possible null exeptions behoben
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 45s
Gitea CI/CD / Set Tag Name (push) Successful in 4s
Gitea CI/CD / docker-build-and-push (push) Successful in 6m5s
Gitea CI/CD / Create Tag (push) Successful in 5s
2025-11-09 00:29:50 +01:00
e5b17d0daf .env Datei entfernt 2025-11-09 00:24:41 +01:00
c2aac1a3a3 Schriftfarbe der Container-Überschrift angepasst 2025-11-09 00:24:31 +01:00
3c6bd2fa56 .env aus compose entfernt 2025-11-09 00:24:17 +01:00
39 changed files with 2020 additions and 360 deletions

View File

@@ -18,19 +18,33 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0
# Build-Argument für Version (wird zur Build-Zeit vom CI/CD gesetzt) # Build-Argument für Version (wird zur Build-Zeit vom CI/CD gesetzt)
ARG VERSION=latest ARG VERSION=latest
# Build-Argumente für UID/GID (Standard: 1000)
ARG USER_UID=1000
ARG USER_GID=1000
# Install curl for health checks
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
# Create non-root user with configurable UID/GID
RUN groupadd -r watcher -g ${USER_GID} && useradd -r -g watcher -u ${USER_UID} watcher
WORKDIR /app WORKDIR /app
COPY --from=build /app/publish . COPY --from=build /app/publish .
# Stelle sicher, dass Verzeichnisse existieren # Stelle sicher, dass Verzeichnisse existieren und Berechtigungen gesetzt sind
RUN mkdir -p /app/persistence /app/wwwroot/downloads/sqlite /app/logs RUN mkdir -p /app/persistence /app/wwwroot/downloads/sqlite /app/logs && \
chown -R watcher:watcher /app
# Volumes # Volumes
VOLUME ["/app/persistence", "/app/wwwroot/downloads/sqlite", "/app/logs"] VOLUME ["/app/persistence", "/app/wwwroot/downloads/sqlite", "/app/logs"]
# Switch to non-root user
USER watcher
# Expose Port 5000 # Expose Port 5000
EXPOSE 5000 EXPOSE 5000
ENV ASPNETCORE_URLS=http://*:5000 ENV ASPNETCORE_URLS=http://*:5000
ENV ASPNETCORE_ENVIRONMENT=Development ENV ASPNETCORE_ENVIRONMENT=Production
# Version als Environment Variable setzen # Version als Environment Variable setzen
ENV WATCHER_VERSION=${VERSION} ENV WATCHER_VERSION=${VERSION}

343
Planung/TODO.md Normal file
View File

@@ -0,0 +1,343 @@
# Watcher - Probleme und TODO-Liste
**Stand:** 2025-11-19
**Analyse:** Automatische Code-Review
---
## 🔴 KRITISCHE PROBLEME (Sofort beheben!)
### 1. Schwerwiegender Bug: Passwort überschreibt Username
- **Datei:** `Watcher/Controllers/UserController.cs:111`
- **Problem:** `user.Username = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);`
- **Auswirkung:** Beim Passwort-Ändern wird der Username zerstört, Account wird unbrauchbar
- **Fix:** Muss `user.Password = ...` sein
- **Status:** ❌ Offen
- **Priorität:** KRITISCH
### 2. Path Traversal Schwachstelle
- **Datei:** `Watcher/Controllers/DownloadController.cs:24-35`
- **Problem:**
- Keine Validierung gegen `../` Attacken
- Leerer String als Extension erlaubt
- Kommentar im Code: "TODO: aktuelles "" für Binaries ist das absolute Gegenteil von sicher"
- **Auswirkung:** Angreifer könnten beliebige Dateien herunterladen
- **Status:** ❌ Offen
- **Priorität:** KRITISCH
### 3. Ungeschützte Monitoring-Endpoints
- **Dateien:**
- `Watcher/Controllers/MonitoringController.cs:112,155,173,237,365`
- `Watcher/Controllers/HeartbeatController.cs:31`
- `Watcher/Controllers/ApiController.cs:26`
- **Problem:** KEINE Authentifizierung
- **Auswirkung:** Jeder kann:
- Fake Server registrieren
- Monitoring-Daten manipulieren
- Alle Server-Informationen abrufen
- Heartbeats senden
- **Fix:** API-Key oder Token-basierte Authentifizierung implementieren
- **Status:** ❌ Offen
- **Priorität:** KRITISCH
### 4. Command Injection
- **Datei:** `Watcher/Controllers/DatabaseController.cs:176-184`
- **Problem:** Unvalidierter `fileName` in `sqlite3` Prozess-Aufruf
- **Auswirkung:** Potenzielle Command Injection beim Database Restore
- **Fix:** Input-Validierung und Sanitization
- **Status:** ❌ Offen
- **Priorität:** KRITISCH
---
## 🟠 HOHE PRIORITÄT
### 5. HttpClient Resource Leak
- **Datei:** `Watcher/Services/UpdateCheckService.cs:24`
- **Problem:** `new HttpClient()` im Singleton-Konstruktor
- **Auswirkung:** Socket Exhaustion bei vielen Requests möglich
- **Fix:** `IHttpClientFactory` verwenden
- **Status:** ❌ Offen
- **Priorität:** HOCH
### 6. Default Credentials in Production
- **Datei:** `Watcher/Program.cs:127-137`
- **Problem:** Standard-User "admin/changeme" wird immer erstellt
- **Auswirkung:** Bekannte Credentials, Sicherheitsrisiko
- **Fix:**
- Beim ersten Start Passwort abfragen
- Oder aus Environment Variable lesen
- Oder zufälliges Passwort generieren und loggen
- **Status:** ❌ Offen
- **Priorität:** HOCH
### 7. Race Conditions in Singleton Stores
- **Dateien:**
- `Watcher/Services/DashboardStore.cs`
- `Watcher/Services/UpdateCheckStore.cs`
- **Problem:** Properties werden ohne Thread-Synchronisation von Background Services geschrieben und von Controllern gelesen
- **Fix:** Lock-Mechanismus oder Concurrent Collections verwenden
- **Status:** ❌ Offen
- **Priorität:** HOCH
### 8. N+1 Query Problem
- **Datei:** `Watcher/Controllers/ServerController.cs:206-212`
- **Problem:** `SaveChangesAsync()` in foreach-Loop
- **Code:**
```csharp
foreach (var server in servers)
{
server.IsOnline = (DateTime.UtcNow - server.LastSeen).TotalSeconds <= 120;
await _context.SaveChangesAsync(); // In Loop!
}
```
- **Auswirkung:** Ineffizient, potenzielle Database Locks
- **Fix:** Alle Änderungen sammeln, einmal am Ende speichern
- **Status:** ❌ Offen
- **Priorität:** HOCH
### 9. Synchrone DB-Abfragen in async Methoden
- **Datei:** `Watcher/Controllers/UserController.cs:28,53,73,101`
- **Problem:** `FirstOrDefault()` statt `FirstOrDefaultAsync()`
- **Auswirkung:** Thread-Pool wird blockiert, reduziert Skalierbarkeit
- **Fix:** Async-Varianten verwenden
- **Status:** ❌ Offen
- **Priorität:** HOCH
### 10. Ineffiziente Database Queries
- **Datei:** `Watcher/Controllers/HomeController.cs:77-78`
- **Problem:** `ToList()` lädt ALLE Daten vor Filterung
- **Code:**
```csharp
var servers = _context.Servers.ToList();
var containers = _context.Containers.ToList();
```
- **Auswirkung:** Memory-Probleme bei vielen Datensätzen
- **Fix:** Filter in LINQ-Query vor `ToList()`
- **Status:** ❌ Offen
- **Priorität:** HOCH
### 11. Database Connections nicht immer mit using
- **Datei:** `Watcher/Services/DatabaseCheck.cs:33-59`
- **Problem:** Connection wird manuell geschlossen, bei Exception könnte sie offen bleiben
- **Fix:** `using` Statement verwenden
- **Status:** ❌ Offen
- **Priorität:** HOCH
---
## 🟡 MITTLERE PRIORITÄT
### Code-Qualität
#### 12. Generische catch-Blöcke ohne Exception-Logging
- **Dateien:**
- `Watcher/Services/NetworkCheck.cs:47`
- `Watcher/Controllers/MonitoringController.cs:222-228`
- **Problem:** Leere catch-Blöcke verschlucken alle Exceptions
- **Fix:** Spezifischen Exception-Typ verwenden und Exception loggen
- **Status:** ❌ Offen
#### 13. Code-Duplikation in UserController
- **Datei:** `Watcher/Controllers/UserController.cs:64-90 und 93-119`
- **Problem:** Zwei fast identische Methoden `Edit()` und `UserSettings()`
- **Fix:** Gemeinsame Logik extrahieren
- **Status:** ❌ Offen
#### 14. Sehr große Controller-Methode
- **Datei:** `Watcher/Controllers/MonitoringController.cs:237-362`
- **Problem:** ServiceDetection mit 125 Zeilen, viele Verantwortlichkeiten
- **Fix:** In kleinere Methoden aufteilen, Service-Klasse extrahieren
- **Status:** ❌ Offen
#### 15. Magic Numbers
- **Dateien:**
- `Watcher/Controllers/ServerController.cs:210` - `120` Sekunden hardcodiert
- `Watcher/Services/NetworkCheck.cs:35` - `"8.8.8.8"` hardcodiert
- `Watcher/Services/NetworkCheck.cs:40` - `3000` ms Timeout hardcodiert
- **Fix:** Als Konstanten oder Konfiguration auslagern
- **Status:** ❌ Offen
#### 16. Duplizierte Endpoint-Logik
- **Datei:** `Watcher/Controllers/MonitoringController.cs:421-481`
- **Problem:** GetCpuUsageData, GetRamUsageData, GetGpuUsageData sind nahezu identisch
- **Fix:** Generische Methode mit Parameter
- **Status:** ❌ Offen
#### 17. Synchrone I/O in async Methoden
- **Datei:** `Watcher/Controllers/DatabaseController.cs:46,69,137,149,151,163,174`
- **Problem:** `File.ReadAllBytes()`, `File.Exists()` etc. sind synchron
- **Fix:** Async File I/O verwenden
- **Status:** ❌ Offen
### Sicherheit
#### 18. Kein Brute-Force Schutz
- **Datei:** `Watcher/Controllers/AuthController.cs:36-72`
- **Problem:** Login hat keine Rate-Limiting, Account Lockout oder CAPTCHA
- **Fix:** Rate-Limiting Middleware oder Account Lockout implementieren
- **Status:** ❌ Offen
#### 19. SQL Injection Potential
- **Datei:** `Watcher/Controllers/DatabaseController.cs:91`
- **Problem:** String-Interpolation für SQL-Query: `$"SELECT * FROM {tableName}"`
- **Hinweis:** tableName kommt aus sqlite_master, aber schlechte Praxis
- **Fix:** Parametrisierte Queries verwenden
- **Status:** ❌ Offen
#### 20. Fehlende IP-Adress-Validierung
- **Datei:** `Watcher/Controllers/MonitoringController.cs:129,159,262`
- **Problem:** IP-Adressen werden nicht validiert
- **Fix:** Regex oder IPAddress.TryParse verwenden
- **Status:** ❌ Offen
### Architektur
#### 21. Kein Repository Pattern
- **Problem:** DbContext direkt in allen Controllern
- **Auswirkung:** Schwer testbar, keine Abstraktionsschicht
- **Fix:** Repository Pattern oder CQRS implementieren
- **Status:** ❌ Offen
#### 22. Hardcodierte Connection Strings
- **Dateien:**
- `Watcher/Services/DatabaseCheck.cs:33`
- `Watcher/Controllers/SystemController.cs:37`
- **Problem:** `"Data Source=./persistence/watcher.db"` hardcodiert
- **Fix:** Aus Configuration/appsettings.json lesen
- **Status:** ❌ Offen
#### 23. Keine Dependency Inversion
- **Problem:** Keine Interfaces für Repositories, direkte DbContext-Abhängigkeit
- **Fix:** Interface-basierte Dependency Injection
- **Status:** ❌ Offen
### Performanz
#### 24. Fehlende Database Indizes
- **Problem:** Keine expliziten Indizes für häufig abgefragte Felder
- **Beispiele:** Server.IPAddress, Container.ContainerId
- **Fix:** Indizes in DbContext konfigurieren
- **Status:** ❌ Offen
#### 25. Keine Caching-Strategie
- **Problem:** Metrics werden jedes Mal neu aus DB geladen
- **Fix:** In-Memory Cache für Current Metrics implementieren
- **Status:** ❌ Offen
#### 26. Mehrfache SaveChanges in Loop
- **Datei:** `Watcher/Controllers/MonitoringController.cs:327,349,359`
- **Problem:** SaveChanges wird in Loop aufgerufen
- **Fix:** Batch-Updates am Ende
- **Status:** ❌ Offen
---
## 🔵 NIEDRIGE PRIORITÄT / WARTBARKEIT
### 27. Keine Unit Tests
- **Problem:** Keine Test-Dateien in der Codebase
- **Auswirkung:** Keine automatisierte Qualitätssicherung
- **Fix:** xUnit/NUnit Test-Suite aufbauen
- **Status:** ❌ Offen
### 28. Fehlende Integration Tests
- **Problem:** Kritische Flows wie Login, Monitoring-Daten-Empfang sind ungetestet
- **Fix:** Integration Tests schreiben
- **Status:** ❌ Offen
### 29. Unvollständige TODOs im Code
- **Dateien:**
- `MonitoringController.cs:287` - "TODO entfernen wenn fertig getestet"
- `MonitoringController.cs:352` - "//Todo" (Metrics für Container entfernen)
- `MonitoringController.cs:525` - "//TODO" (CalculateMegabit korrekt implementieren)
- `DownloadController.cs:28` - "TODO: aktuelles "" für Binaries ist das absolute Gegenteil von sicher"
- `DatabaseCheck.cs:61` - "// TODO: LogEvent erstellen"
- `SystemMangement.cs:20` - "// Todo: Umstellen auf einmal alle 24h"
- **Fix:** TODOs abarbeiten oder entfernen
- **Status:** ❌ Offen
### 30. Fehlende XML-Dokumentation
- **Problem:** Keine `///` Kommentare für öffentliche APIs
- **Fix:** XML-Kommentare für Controllers und Services hinzufügen
- **Status:** ❌ Offen
### 31. Console.WriteLine in Production
- **Dateien:**
- `Program.cs:121,125,137,141`
- `MonitoringController.cs:288-293`
- **Problem:** Console.WriteLine statt strukturiertes Logging
- **Fix:** ILogger verwenden
- **Status:** ❌ Offen
### 32. Inkonsistente Namenskonventionen
- **Datei:** `MonitoringController.cs:53-81`
- **Problem:** MetricDto Properties in UPPERCASE (CPU_Load, RAM_Size)
- **Fix:** PascalCase verwenden (CpuLoad, RamSize)
- **Status:** ❌ Offen
---
## 📊 STATISTIK
- **Kritische Probleme:** 4
- **Hohe Priorität:** 7
- **Mittlere Priorität:** 18
- **Niedrige Priorität:** 6
- **Gesamt:** 35 Probleme
---
## 🎯 EMPFOHLENE REIHENFOLGE
### Sprint 1 - Kritische Sicherheit (Sofort)
1. Bug in UserController.cs Zeile 111 beheben
2. Authentifizierung für Monitoring-Endpoints
3. Path Traversal Validierung in DownloadController
4. Command Injection in DatabaseController beheben
### Sprint 2 - Stabilität & Performance (Woche 1-2)
5. HttpClientFactory implementieren
6. N+1 Query Probleme beheben
7. Async/Await korrekt verwenden
8. Database Connection Management
### Sprint 3 - Sicherheit & Konfiguration (Woche 3-4)
9. Default Credentials entfernen/anpassbar machen
10. Input-Validierung verbessern
11. Brute-Force Protection
12. Thread-Safety in Stores
### Sprint 4 - Architektur (Monat 2)
13. Repository Pattern einführen
14. Code-Duplikation eliminieren
15. Große Methoden refactoren
16. Magic Numbers entfernen
### Sprint 5 - Qualität (Monat 3)
17. Test-Suite aufbauen (Unit + Integration)
18. Statische Code-Analyse einrichten
19. TODOs abarbeiten
20. Dokumentation verbessern
---
## 🔧 TOOLS & HILFSMITTEL
### Empfohlene Tools
- **Statische Analyse:** SonarQube, Roslyn Analyzers
- **Security Scanning:** OWASP Dependency Check, Snyk
- **Testing:** xUnit, Moq, FluentAssertions
- **Code Coverage:** Coverlet, ReportGenerator
- **Performance:** BenchmarkDotNet, MiniProfiler
### Code-Qualität Metriken
- **Zyklomatische Komplexität:** < 10 pro Methode
- **Zeilen pro Methode:** < 50
- **Test Coverage:** > 80%
- **Code Duplication:** < 5%
---
**Letzte Aktualisierung:** 2025-11-19
**Erstellt durch:** Automatische Code-Analyse

121
README.md
View File

@@ -1,34 +1,111 @@
# 🖥️ Server Monitoring Software # Watcher - Server Monitoring Solution
Dieses Projekt ist eine umfassende Monitoring-Lösung für Server und Host-Geräte. [![Build Status](https://git.triggermeelmo.com/Watcher/watcher/badges/workflows/build.yml/badge.svg)](https://git.triggermeelmo.com/Watcher/watcher/actions)
Die Software besteht aus zwei Teilen: [![.NET Version](https://img.shields.io/badge/.NET-8.0-512BD4?logo=dotnet)](https://dotnet.microsoft.com/)
- **Host Agent**: Sammelt Hardware-Daten von den Hosts [![Docker Image](https://img.shields.io/badge/docker-multi--arch-2496ED?logo=docker)](https://git.triggermeelmo.com/watcher/-/packages/container/watcher-server)
- **Zentrale Monitoring-Software**: Visualisiert und verwaltet die gesammelten Daten [![Platform](https://img.shields.io/badge/platform-linux%2Famd64%20%7C%20linux%2Farm64-lightgrey)](https://git.triggermeelmo.com/watcher/watcher-server)
Die Lösung unterstützt moderne Authentifizierungsverfahren und flexible Datenbankanbindungen alles bequem verteilt als Docker Image. **Watcher** ist eine umfassende Server- und Host-Monitoring-Lösung mit verteilter Architektur, die Echtzeit-Hardware-Metriken erfasst und über ein zentrales Web-Dashboard visualisiert.
--- ## 📋 Überblick
## ✨ Features Die Software besteht aus zwei Hauptkomponenten:
- Erfassung von Hardware-Daten aller wichtigen Komponenten - **Host Agent**: Sammelt Hardware-Metriken (CPU, GPU, RAM, Festplatte, Netzwerk) von den überwachten Servern
- Lokale Authentifizierung oder OIDC (OpenID Connect) - **Zentrale Monitoring-Software**: Web-basiertes Dashboard zur Visualisierung und Verwaltung der gesammelten Daten
- Wahlweise Speicherung der Daten in:
- Lokaler SQLite-Datenbank
- Remote MySQL-Datenbank
- Einfache Bereitstellung via Docker & docker-compose
--- ### Hauptfunktionen
- Echtzeit-Hardware-Monitoring (CPU, GPU, RAM, Festplatte, Netzwerk)
- Docker-Container-Überwachung mit Service Discovery
- Web-basiertes Dashboard mit historischen Daten
- Konfigurierbare Alarmschwellen
- REST API mit Swagger-Dokumentation
- Automatische Datenaufbewahrung (konfigurierbar)
- Rootless Container-Betrieb für erhöhte Sicherheit
## ⚙️ Installation & Start ## 🚀 Installation & Start
Voraussetzung: ### Voraussetzungen
- [Docker](https://www.docker.com/) - [Docker](https://www.docker.com/)
- [docker-compose](https://docs.docker.com/compose/) - [Docker Compose](https://docs.docker.com/compose/)
1. Image herunterladen: ### Schnellstart
1. **Repository klonen oder docker-compose.yaml herunterladen**
```bash ```bash
docker pull git.triggermeelmo.com/daniel-hbn/watcher/watcher:latest git clone https://git.triggermeelmo.com/Watcher/watcher.git
2. Docker Container starten cd watcher
```
2. **Umgebungsvariablen konfigurieren (optional)**
```bash ```bash
docker compose up -d # .env Datei erstellen
cp .env.example .env
# Eigene UID/GID eintragen (für korrekte Dateiberechtigungen)
echo "USER_UID=$(id -u)" >> .env
echo "USER_GID=$(id -g)" >> .env
```
3. **Verzeichnisse mit korrekten Rechten erstellen**
```bash
mkdir -p data/db data/dumps data/logs
chown -R $(id -u):$(id -g) data/
```
4. **Container starten**
```bash
docker compose up -d
```
5. **Dashboard aufrufen**
```
http://localhost:5000
```
6. **Standardanmeldung**
- Benutzername: `admin`
- Passwort: `changeme`
- ⚠️ **Wichtig:** Passwort nach dem ersten Login ändern!
### Konfiguration
#### Wichtige Umgebungsvariablen
| Variable | Beschreibung | Standard |
|----------|--------------|----------|
| `USER_UID` | User-ID für Container (Dateiberechtigungen) | `1000` |
| `USER_GID` | Gruppen-ID für Container | `1000` |
| `IMAGE_VERSION` | Docker Image Version | `latest` |
| `METRIC_RETENTION_DAYS` | Datenspeicherdauer (Tage) | `30` |
| `METRIC_CLEANUP_ENABLED` | Automatische Datenbereinigung | `true` |
| `FRONTEND_REFRESH_INTERVAL_SECONDS` | Dashboard Aktualisierungsrate | `30` |
Vollständige Liste: siehe `docker-compose.yaml`
#### Volumes
- `./data/db` → `/app/persistence` - SQLite-Datenbank
- `./data/dumps` → `/app/wwwroot/downloads/sqlite` - Datenbank-Exports
- `./data/logs` → `/app/logs` - Anwendungslogs
#### Sicherheit
Der Container läuft als **non-root user** mit konfigurierbarer UID/GID:
- Standard: `1000:1000`
- Anpassbar über `USER_UID` und `USER_GID` in `.env`
- Empfehlung: Eigene UID/GID verwenden für korrekte Dateiberechtigungen
## 📝 Lizenz
Dieses Projekt ist unter einer proprietären Lizenz lizenziert.
## 🔗 Links
- **Repository:** [https://git.triggermeelmo.com/Watcher/watcher](https://git.triggermeelmo.com/Watcher/watcher)
- **Container Registry:** [https://git.triggermeelmo.com/watcher/-/packages/container/watcher-server](https://git.triggermeelmo.com/watcher/-/packages/container/watcher-server)
- **Issue Tracker:** [https://git.triggermeelmo.com/Watcher/watcher/issues](https://git.triggermeelmo.com/Watcher/watcher/issues)
---
**Entwickelt mit ❤️ unter Verwendung von .NET 8.0**

View File

@@ -1,19 +0,0 @@
# Application Version
# Bei lokalem Development wird "development" angezeigt, im Docker-Container die Image-Version
WATCHER_VERSION=development
# Update Check
# Überprüft täglich, ob eine neue Version verfügbar ist
UPDATE_CHECK_ENABLED=true
UPDATE_CHECK_INTERVAL_HOURS=24
UPDATE_CHECK_REPOSITORY_URL=https://git.triggermeelmo.com/api/v1/repos/Watcher/watcher/releases/latest
# Data Retention Policy
# Wie lange sollen Metriken gespeichert werden (in Tagen)?
METRIC_RETENTION_DAYS=30
# Wie oft soll der Cleanup-Prozess laufen (in Stunden)?
METRIC_CLEANUP_INTERVAL_HOURS=24
# Soll der Cleanup-Service aktiviert sein?
METRIC_CLEANUP_ENABLED=true

View File

@@ -27,6 +27,6 @@ public class ApiController : Controller
public async Task<IActionResult> GetAllServers() public async Task<IActionResult> GetAllServers()
{ {
var Servers = await _context.Servers.OrderBy(s => s.Id).ToListAsync(); var Servers = await _context.Servers.OrderBy(s => s.Id).ToListAsync();
return Ok(); return Ok(Servers);
} }
} }

View File

@@ -19,14 +19,18 @@ namespace Watcher.Controllers
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
// Daten der Backgroundchecks abrufen // Daten der Backgroundchecks abrufen
private IDashboardStore _DashboardStore; private IDashboardStore _dashboardStore;
// System Store für Konfigurationen
private ISystemStore _systemStore;
// HomeController Constructor // HomeController Constructor
public HomeController(AppDbContext context, ILogger<HomeController> logger, IDashboardStore dashboardStore) public HomeController(AppDbContext context, ILogger<HomeController> logger, IDashboardStore dashboardStore, ISystemStore systemStore)
{ {
_context = context; _context = context;
_logger = logger; _logger = logger;
_DashboardStore = dashboardStore; _dashboardStore = dashboardStore;
_systemStore = systemStore;
} }
@@ -58,8 +62,9 @@ namespace Watcher.Controllers
Containers = await _context.Containers Containers = await _context.Containers
.OrderBy(s => s.Name) .OrderBy(s => s.Name)
.ToListAsync(), .ToListAsync(),
NetworkStatus = _DashboardStore.NetworkStatus, NetworkStatus = _dashboardStore.NetworkStatus,
DatabaseStatus = _DashboardStore.DatabaseStatus DatabaseStatus = _dashboardStore.DatabaseStatus,
RefreshIntervalMilliseconds = _systemStore.FrontendRefreshIntervalMilliseconds
}; };
//ViewBag.NetworkConnection = _NetworkCheckStore.NetworkStatus; //ViewBag.NetworkConnection = _NetworkCheckStore.NetworkStatus;
return View(viewModel); return View(viewModel);
@@ -90,14 +95,14 @@ namespace Watcher.Controllers
Containers = await _context.Containers Containers = await _context.Containers
.OrderBy(s => s.Name) .OrderBy(s => s.Name)
.ToListAsync(), .ToListAsync(),
NetworkStatus = _DashboardStore.NetworkStatus, NetworkStatus = _dashboardStore.NetworkStatus,
DatabaseStatus = _DashboardStore.DatabaseStatus DatabaseStatus = _dashboardStore.DatabaseStatus
}; };
return PartialView("_DashboardStats", model); return PartialView("_DashboardStats", model);
} }
public String ReturnNetworkStatus() public string ReturnNetworkStatus()
{ {
return "OK"; return "OK";
} }

View File

@@ -83,7 +83,8 @@ public class MetricDto
public class DockerServiceDto public class DockerServiceDto
{ {
public required int Server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts public int Server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts (optional, falls der Agent diese bereits kennt)
public string? IpAddress { get; set; } // IP-Adresse des Servers (wird verwendet, falls Server_id nicht gesetzt oder 0 ist)
public required JsonElement Containers { get; set; } public required JsonElement Containers { get; set; }
} }
@@ -107,7 +108,7 @@ public class MonitoringController : Controller
} }
// Endpoint, an den der Agent seine Hardwareinformationen schickt // Endpoint, an den der Agent seine Hardwareinformationen schickt (Registrierung Schritt 2)
[HttpPost("hardware-info")] [HttpPost("hardware-info")]
public async Task<IActionResult> Register([FromBody] HardwareDto dto) public async Task<IActionResult> Register([FromBody] HardwareDto dto)
{ {
@@ -138,15 +139,19 @@ public class MonitoringController : Controller
// Änderungen in Datenbank speichern // Änderungen in Datenbank speichern
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
// Success // Success - Server-ID und IP-Adresse zurückgeben
_logger.LogInformation("Agent für '{server}' erfolgreich registriert.", server.Name); _logger.LogInformation("Agent für '{server}' erfolgreich registriert.", server.Name);
return Ok(); return Ok(new
{
id = server.Id,
ipAddress = server.IPAddress
});
} }
_logger.LogError("Kein Server für Registrierung gefunden"); _logger.LogError("Kein Server für Registrierung gefunden");
return NotFound("No Matching Server found."); return NotFound("No Matching Server found.");
} }
// Endpoint, an dem sich ein Agent initial registriert // Endpoint, an dem sich ein Agent seine ID abholt (Registrierung Schritt 1)
[HttpGet("register")] [HttpGet("register")]
public async Task<IActionResult> GetServerIdByIp([FromQuery] string IpAddress) public async Task<IActionResult> GetServerIdByIp([FromQuery] string IpAddress)
{ {
@@ -180,52 +185,60 @@ public class MonitoringController : Controller
return BadRequest(new { error = "Ungültiger Payload", details = errors }); return BadRequest(new { error = "Ungültiger Payload", details = errors });
} }
// Server in Datenbank finden // Debug-Logging
var server = await _context.Servers _logger.LogDebug("Metric Request empfangen: ServerId={ServerId}, IpAddress={IpAddress}",
.FirstOrDefaultAsync(s => s.IPAddress == dto.IpAddress); dto.ServerId, dto.IpAddress ?? "null");
if (server != null) // Server in Datenbank finden (priorisiert IP-Adresse, dann ID)
_logger.LogInformation("ServerID: {ServerId}", dto.ServerId);
var server = await FindServerByIpOrId(dto.ServerId);
if (server == null)
{ {
// neues Metric-Objekt erstellen _logger.LogError("Kein Server mit IP '{IpAddress}' oder ID {ServerId} gefunden",
var NewMetric = new Metric dto.IpAddress, dto.ServerId);
{ return NotFound(new {
Timestamp = DateTime.UtcNow, error = "Server not found",
ServerId = dto.ServerId, details = $"Server mit ID {dto.ServerId} existiert nicht. Bitte zuerst registrieren."
CPU_Load = sanitizeInput(dto.CPU_Load), });
CPU_Temp = sanitizeInput(dto.CPU_Temp),
GPU_Load = sanitizeInput(dto.GPU_Load),
GPU_Temp = sanitizeInput(dto.GPU_Temp),
GPU_Vram_Size = calculateGigabyte(dto.GPU_Vram_Size),
GPU_Vram_Usage = sanitizeInput(dto.GPU_Vram_Load),
RAM_Load = sanitizeInput(dto.RAM_Load),
RAM_Size = calculateGigabyte(dto.RAM_Size),
DISK_Size = calculateGigabyte(dto.DISK_Size),
DISK_Usage = calculateGigabyte(dto.DISK_Usage),
DISK_Temp = sanitizeInput(dto.DISK_Temp),
NET_In = calculateMegabit(dto.NET_In),
NET_Out = calculateMegabit(dto.NET_Out)
};
try
{
// Metric Objekt in Datenbank einfügen
_context.Metrics.Add(NewMetric);
await _context.SaveChangesAsync();
_logger.LogInformation("Monitoring-Daten für '{server}' empfangen", server.Name);
return Ok();
}
catch
{
// Alert triggern
_logger.LogError("Metric für {server} konnte nicht in Datenbank geschrieben werden.", server.Name);
return BadRequest();
}
} }
_logger.LogError("Kein Server für eingegangenen Monitoring-Payload gefunden"); // neues Metric-Objekt erstellen
return NotFound("No Matching Server found."); var newMetric = new Metric
{
Timestamp = DateTime.UtcNow,
ServerId = server.Id, // Verwende die tatsächliche Server-ID aus der DB
CPU_Load = SanitizeInput(dto.CPU_Load),
CPU_Temp = SanitizeInput(dto.CPU_Temp),
GPU_Load = SanitizeInput(dto.GPU_Load),
GPU_Temp = SanitizeInput(dto.GPU_Temp),
GPU_Vram_Size = CalculateGigabyte(dto.GPU_Vram_Size),
GPU_Vram_Usage = SanitizeInput(dto.GPU_Vram_Load),
RAM_Load = SanitizeInput(dto.RAM_Load),
RAM_Size = CalculateGigabyte(dto.RAM_Size),
DISK_Size = CalculateGigabyte(dto.DISK_Size),
DISK_Usage = CalculateGigabyte(dto.DISK_Usage),
DISK_Temp = SanitizeInput(dto.DISK_Temp),
NET_In = CalculateMegabit(dto.NET_In),
NET_Out = CalculateMegabit(dto.NET_Out)
};
try
{
// Metric Objekt in Datenbank einfügen
_context.Metrics.Add(newMetric);
await _context.SaveChangesAsync();
_logger.LogInformation("Monitoring-Daten für Server '{ServerName}' (ID: {ServerId}) in Datenbank geschrieben",
server.Name, server.Id);
return Ok();
}
catch (Exception ex)
{
_logger.LogError(ex, "Metric für Server '{ServerName}' (ID: {ServerId}) konnte nicht gespeichert werden",
server.Name, server.Id);
return StatusCode(500, new { error = "Database error", details = ex.Message });
}
} }
// Endpoint, an dem Agents Ihre laufenden Services registrieren // Endpoint, an dem Agents Ihre laufenden Services registrieren
@@ -244,45 +257,66 @@ public class MonitoringController : Controller
return BadRequest(new { error = "Invalid Payload", details = errors }); return BadRequest(new { error = "Invalid Payload", details = errors });
} }
// Prüfen, ob der Server existiert // Debug-Logging für eingehende Requests
var serverExists = await _context.Servers.AnyAsync(s => s.Id == dto.Server_id); _logger.LogDebug("Service-Discovery Request empfangen: Server_id={ServerId}, IpAddress={IpAddress}",
if (!serverExists) dto.Server_id, dto.IpAddress ?? "null");
// Server in Datenbank finden (priorisiert IP-Adresse, dann ID)
var server = await FindServerByIpOrId(dto.Server_id);
if (server == null)
{ {
_logger.LogError($"Server with ID {dto.Server_id} does not exist."); _logger.LogError("Server with IP '{IpAddress}' or ID {ServerId} does not exist.",
return BadRequest(new { error = "Server not found", details = $"Server with ID {dto.Server_id} does not exist. Please register the server first." }); dto.IpAddress, dto.Server_id);
return BadRequest(new {
error = "Server not found",
details = $"Server with IP '{dto.IpAddress}' or ID {dto.Server_id} does not exist. Please register the server first."
});
} }
// Server ID für die weitere Verarbeitung setzen
int serverId = server.Id;
List<Container> newContainers = List<Container> newContainers =
JsonSerializer.Deserialize<List<Container>>(dto.Containers.GetRawText()) JsonSerializer.Deserialize<List<Container>>(dto.Containers.GetRawText())
?? new List<Container>(); ?? new List<Container>();
foreach (Container c in newContainers) foreach (Container container in newContainers)
{ {
c.ServerId = dto.Server_id; container.ServerId = serverId;
// Debug Logs // Debug Logs
// TODO entfernen wenn fertig getestet // TODO entfernen wenn fertig getestet
Console.WriteLine("---------"); Console.WriteLine("---------");
Console.WriteLine("ServerId: " + c.ServerId); Console.WriteLine("ServerId: " + container.ServerId);
Console.WriteLine("ContainerId: " + c.ContainerId); Console.WriteLine("ContainerId: " + container.ContainerId);
Console.WriteLine("Name: " + c.Name); Console.WriteLine("Name: " + container.Name);
Console.WriteLine("Image: " + c.Image); Console.WriteLine("Image: " + container.Image);
Console.WriteLine("---------"); Console.WriteLine("---------");
} }
// Liste aller Container, die bereits der übergebenen ServerId zugewiesen sind // Liste aller Container, die bereits der übergebenen ServerId zugewiesen sind
List<Container> existingContainers = _context.Containers List<Container> existingContainers = _context.Containers
.Where(c => c.ServerId == dto.Server_id) .Where(c => c.ServerId == serverId)
.ToList(); .ToList();
// Logik, um Container, die mit dem Payload kamen zu verarbeiten // Logik, um Container, die mit dem Payload kamen zu verarbeiten
foreach (Container c in newContainers) foreach (Container container in newContainers)
{ {
// Überprüfen, ob ein übergebener Container bereits für den Host registriert ist // Überprüfen, ob ein übergebener Container bereits für den Host registriert ist
if (existingContainers.Contains(c)) // Wichtig: Vergleich über ContainerId, nicht über Objektreferenz!
var existingContainer = existingContainers
.FirstOrDefault(ec => ec.ContainerId == container.ContainerId);
if (existingContainer != null)
{ {
_logger.LogInformation("Container with id " + c.ContainerId + " already exists."); // Container existiert bereits, nur Daten aktualisieren falls sich etwas geändert hat
existingContainer.Name = container.Name;
existingContainer.Image = container.Image;
existingContainer.IsRunning = true;
_logger.LogInformation("Container '{containerName}' (ID: {containerId}) already exists for Server {serverId}, updated.", container.Name, container.ContainerId, serverId);
} }
// Container auf einen Host/Server registrieren // Container auf einen Host/Server registrieren
else else
@@ -290,34 +324,41 @@ public class MonitoringController : Controller
// Container in Datenbank einlesen // Container in Datenbank einlesen
try try
{ {
_context.Containers.Add(c); _context.Containers.Add(container);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
_logger.LogInformation(c.Name + " added for Host " + c.ServerId); _logger.LogInformation("Container '{containerName}' (ID: {containerId}) added for Server {serverId}", container.Name, container.ContainerId, container.ServerId);
} }
catch (SqliteException e) catch (SqliteException e)
{ {
_logger.LogError("Error writing new Containers to Database: " + e.Message); _logger.LogError("Error writing new Container '{containerName}' to Database: {error}", container.Name, e.Message);
} }
} }
} }
// Logik um abgeschaltene Container aus der Datenbank zu entfernen // Logik um abgeschaltene Container aus der Datenbank zu entfernen
foreach (Container c in existingContainers) foreach (Container existingContainer in existingContainers)
{ {
// Abfrage, ob bereits vorhandener Container im Payload vorhanden war // Abfrage, ob bereits vorhandener Container im Payload vorhanden war
if (!newContainers.Contains(c)) // Wichtig: Vergleich über ContainerId, nicht über Objektreferenz!
var stillRunning = newContainers
.Any(nc => nc.ContainerId == existingContainer.ContainerId);
if (!stillRunning)
{ {
// Container entfernen // Container entfernen
_context.Containers.Remove(c); _context.Containers.Remove(existingContainer);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
// Metrics für den Container entfernen // Metrics für den Container entfernen
//Todo //Todo
_logger.LogInformation("Container " + c.Name + " (" + c.Id + ") on Host-Id " + c.ServerId + " was successfully removed from the database."); _logger.LogInformation("Container '{containerName}' (DB-ID: {id}, ContainerID: {containerId}) on Server {serverId} was removed from the database.", existingContainer.Name, existingContainer.Id, existingContainer.ContainerId, existingContainer.ServerId);
} }
} }
// Alle Änderungen in einem Batch speichern
await _context.SaveChangesAsync();
return Ok(); return Ok();
} }
@@ -377,6 +418,7 @@ public class MonitoringController : Controller
return NotFound(); return NotFound();
} }
[Authorize]
[HttpGet("cpu-usage")] [HttpGet("cpu-usage")]
public async Task<IActionResult> GetCpuUsageData(int serverId, int hours = 1) public async Task<IActionResult> GetCpuUsageData(int serverId, int hours = 1)
{ {
@@ -397,6 +439,7 @@ public class MonitoringController : Controller
return Ok(data); return Ok(data);
} }
[Authorize]
[HttpGet("ram-usage")] [HttpGet("ram-usage")]
public async Task<IActionResult> GetRamUsageData(int serverId, int hours = 1) public async Task<IActionResult> GetRamUsageData(int serverId, int hours = 1)
{ {
@@ -417,6 +460,7 @@ public class MonitoringController : Controller
return Ok(data); return Ok(data);
} }
[Authorize]
[HttpGet("gpu-usage")] [HttpGet("gpu-usage")]
public async Task<IActionResult> GetGpuUsageData(int serverId, int hours = 1) public async Task<IActionResult> GetGpuUsageData(int serverId, int hours = 1)
{ {
@@ -437,40 +481,101 @@ public class MonitoringController : Controller
return Ok(data); return Ok(data);
} }
[Authorize]
[HttpGet("current-metrics/{serverId}")]
public async Task<IActionResult> GetCurrentMetrics(int serverId)
{
var latestMetric = await _context.Metrics
.Where(m => m.ServerId == serverId)
.OrderByDescending(m => m.Timestamp)
.FirstOrDefaultAsync();
if (latestMetric == null)
{
return Ok(new
{
cpu = 0.0,
ram = 0.0,
gpu = 0.0,
hasData = false
});
}
return Ok(new
{
cpu = latestMetric.CPU_Load,
ram = latestMetric.RAM_Load,
gpu = latestMetric.GPU_Load,
hasData = true
});
}
// Metric Input Byte zu Gigabyte umwandeln // Metric Input Byte zu Gigabyte umwandeln
public static double calculateGigabyte(double metric_input) public static double CalculateGigabyte(double metricInput)
{ {
// *10^-9 um auf Gigabyte zu kommen // *10^-9 um auf Gigabyte zu kommen
double calculatedValue = metric_input * Math.Pow(10, -9); double calculatedValue = metricInput * Math.Pow(10, -9);
// Auf 2 Nachkommastellen runden // Auf 2 Nachkommastellen runden
double calculatedValue_s = sanitizeInput(calculatedValue); double calculatedValueSanitized = SanitizeInput(calculatedValue);
return calculatedValue_s; return calculatedValueSanitized;
} }
// Metric Input Byte/s zu Megabit/s umrechnen // Metric Input Byte/s zu Megabit/s umrechnen
//TODO //TODO
public static double calculateMegabit(double metric_input) public static double CalculateMegabit(double metricInput)
{ {
// *10^-9 um auf Gigabyte zu kommen // *10^-9 um auf Gigabyte zu kommen
double calculatedValue = metric_input * Math.Pow(10, -9); double calculatedValue = metricInput * Math.Pow(10, -9);
// Auf 2 Nachkommastellen runden // Auf 2 Nachkommastellen runden
double calculatedValue_s = sanitizeInput(calculatedValue); double calculatedValueSanitized = SanitizeInput(calculatedValue);
return calculatedValue_s; return calculatedValueSanitized;
} }
// Degree Input auf zwei Nachkommastellen runden // Degree Input auf zwei Nachkommastellen runden
public static double sanitizeInput(double metric_input) public static double SanitizeInput(double metricInput)
{ {
Math.Round(metric_input, 2); return Math.Round(metricInput, 2);
return metric_input;
} }
private List<Container> ParseServiceDiscoveryInput(int server_id, List<Container> containers) // ==================== HELPER METHODS ====================
/// <summary>
/// Findet einen Server anhand IP-Adresse oder ID.
/// Priorisiert IP-Adresse, fällt dann auf ID zurück.
/// </summary>
/// <param name="ipAddress">IP-Adresse des Servers (bevorzugt)</param>
/// <param name="serverId">Server-ID (Fallback)</param>
/// <returns>Server-Objekt oder null wenn nicht gefunden</returns>
private async Task<Server> FindServerByIpOrId(int serverId)
{
// WICHTIG: >= 0 da Server-IDs bei 0 starten können
if (serverId >= 0)
{
var server = await _context.Servers
.FirstOrDefaultAsync(s => s.Id == serverId);
if (server != null)
{
_logger.LogDebug("Server gefunden via ID: {ServerName}", server.Name);
return server;
} else {
// Server nicht gefunden
_logger.LogWarning("Server nicht gefunden: ID={ServerId}", serverId);
return null;
}
} else {
_logger.LogWarning("Ungültige ID abgefragt!");
return null;
}
}
private List<Container> ParseServiceDiscoveryInput(int serverId, List<Container> containers)
{ {
List<Container> containerList = new List<Container>(); List<Container> containerList = new List<Container>();

View File

@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Watcher.Data; using Watcher.Data;
using Watcher.Models; using Watcher.Models;
using Watcher.ViewModels; using Watcher.ViewModels;
using Watcher.Services;
[Authorize] [Authorize]
[Route("[controller]")] [Route("[controller]")]
@@ -13,23 +14,27 @@ public class ServerController : Controller
private readonly ILogger<ServerController> _logger; private readonly ILogger<ServerController> _logger;
private readonly ISystemStore _systemStore;
public ServerController(AppDbContext context, ILogger<ServerController> logger)
public ServerController(AppDbContext context, ILogger<ServerController> logger, ISystemStore systemStore)
{ {
_context = context; _context = context;
_logger = logger; _logger = logger;
_systemStore = systemStore;
} }
[HttpGet("Overview")] [HttpGet("Overview")]
public async Task<IActionResult> Overview() public async Task<IActionResult> Overview()
{ {
var vm = new ServerOverviewViewModel var viewModel = new ServerOverviewViewModel
{ {
Servers = await _context.Servers.OrderBy(s => s.Id).ToListAsync() Servers = await _context.Servers.OrderBy(s => s.Id).ToListAsync(),
RefreshIntervalMilliseconds = _systemStore.FrontendRefreshIntervalMilliseconds
}; };
return View(vm); return View(viewModel);
} }
@@ -42,17 +47,17 @@ public class ServerController : Controller
// POST: Server/AddServer // POST: Server/AddServer
[HttpPost("AddServer")] [HttpPost("AddServer")]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> AddServer(AddServerViewModel vm) public async Task<IActionResult> AddServer(AddServerViewModel viewModel)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(vm); return View(viewModel);
var server = new Server var server = new Server
{ {
Name = vm.Name, Name = viewModel.Name,
IPAddress = vm.IPAddress, IPAddress = viewModel.IPAddress,
Type = vm.Type, Type = viewModel.Type,
IsOnline = vm.IsOnline, IsOnline = viewModel.IsOnline,
}; };
_context.Servers.Add(server); _context.Servers.Add(server);
@@ -91,25 +96,39 @@ public class ServerController : Controller
var server = await _context.Servers.FindAsync(id); var server = await _context.Servers.FindAsync(id);
if (server == null) return NotFound(); if (server == null) return NotFound();
var vm = new EditServerViewModel var viewModel = new EditServerViewModel
{ {
Name = server.Name, Name = server.Name,
IPAddress = server.IPAddress, IPAddress = server.IPAddress,
Type = server.Type Type = server.Type,
CpuLoadWarning = server.CpuLoadWarning,
CpuLoadCritical = server.CpuLoadCritical,
CpuTempWarning = server.CpuTempWarning,
CpuTempCritical = server.CpuTempCritical,
RamLoadWarning = server.RamLoadWarning,
RamLoadCritical = server.RamLoadCritical,
GpuLoadWarning = server.GpuLoadWarning,
GpuLoadCritical = server.GpuLoadCritical,
GpuTempWarning = server.GpuTempWarning,
GpuTempCritical = server.GpuTempCritical,
DiskUsageWarning = server.DiskUsageWarning,
DiskUsageCritical = server.DiskUsageCritical,
DiskTempWarning = server.DiskTempWarning,
DiskTempCritical = server.DiskTempCritical
}; };
return View(vm); return View(viewModel);
} }
// POST: Server/Edit/5 // POST: Server/Edit/5
[HttpPost("EditServer/{id}")] [HttpPost("EditServer/{id}")]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> EditServer(int id, EditServerViewModel vm) public async Task<IActionResult> EditServer(int id, EditServerViewModel viewModel)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return View(vm); return View(viewModel);
} }
var server = await _context.Servers.FindAsync(id); var server = await _context.Servers.FindAsync(id);
@@ -118,9 +137,23 @@ public class ServerController : Controller
return NotFound(); return NotFound();
} }
server.Name = vm.Name; server.Name = viewModel.Name;
server.IPAddress = vm.IPAddress; server.IPAddress = viewModel.IPAddress;
server.Type = vm.Type; server.Type = viewModel.Type;
server.CpuLoadWarning = viewModel.CpuLoadWarning;
server.CpuLoadCritical = viewModel.CpuLoadCritical;
server.CpuTempWarning = viewModel.CpuTempWarning;
server.CpuTempCritical = viewModel.CpuTempCritical;
server.RamLoadWarning = viewModel.RamLoadWarning;
server.RamLoadCritical = viewModel.RamLoadCritical;
server.GpuLoadWarning = viewModel.GpuLoadWarning;
server.GpuLoadCritical = viewModel.GpuLoadCritical;
server.GpuTempWarning = viewModel.GpuTempWarning;
server.GpuTempCritical = viewModel.GpuTempCritical;
server.DiskUsageWarning = viewModel.DiskUsageWarning;
server.DiskUsageCritical = viewModel.DiskUsageCritical;
server.DiskTempWarning = viewModel.DiskTempWarning;
server.DiskTempCritical = viewModel.DiskTempCritical;
try try
{ {
@@ -132,7 +165,7 @@ public class ServerController : Controller
{ {
_logger.LogError(ex, "Fehler beim Speichern des Servers"); _logger.LogError(ex, "Fehler beim Speichern des Servers");
ModelState.AddModelError("", "Fehler beim Speichern"); ModelState.AddModelError("", "Fehler beim Speichern");
return View(vm); return View(viewModel);
} }
} }
@@ -142,27 +175,28 @@ public class ServerController : Controller
public async Task<IActionResult> Details(int id) public async Task<IActionResult> Details(int id)
{ {
var s = await _context.Servers.FindAsync(id); var server = await _context.Servers.FindAsync(id);
if (s == null) return NotFound(); if (server == null) return NotFound();
var vm = new ServerDetailsViewModel var viewModel = new ServerDetailsViewModel
{ {
Id = s.Id, Id = server.Id,
Name = s.Name, Name = server.Name,
IPAddress = s.IPAddress, IPAddress = server.IPAddress,
Type = s.Type, Type = server.Type,
Description = s.Description, Description = server.Description,
CpuType = s.CpuType, CpuType = server.CpuType,
CpuCores = s.CpuCores, CpuCores = server.CpuCores,
GpuType = s.GpuType, GpuType = server.GpuType,
RamSize = s.RamSize, RamSize = server.RamSize,
CreatedAt = s.CreatedAt, CreatedAt = server.CreatedAt,
IsOnline = s.IsOnline, IsOnline = server.IsOnline,
LastSeen = s.LastSeen, LastSeen = server.LastSeen,
IsVerified = s.IsVerified IsVerified = server.IsVerified,
RefreshIntervalMilliseconds = _systemStore.FrontendRefreshIntervalMilliseconds
}; };
return View(vm); return View(viewModel);
} }
@@ -177,6 +211,7 @@ public class ServerController : Controller
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }
ViewBag.RefreshIntervalMilliseconds = _systemStore.FrontendRefreshIntervalMilliseconds;
return PartialView("_ServerCard", servers); return PartialView("_ServerCard", servers);
} }

View File

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Watcher.Data; using Watcher.Data;
using Watcher.ViewModels; using Watcher.ViewModels;
@@ -20,12 +21,12 @@ public class UserController : Controller
// Anzeigen der User-Informationen // Anzeigen der User-Informationen
[Authorize] [Authorize]
public IActionResult Info() public async Task<IActionResult> Info()
{ {
var claims = User.Claims.Select(c => new { c.Type, c.Value }).ToList(); var claims = User.Claims.Select(c => new { c.Type, c.Value }).ToList();
var Identity_User = User.Identity?.Name; var Identity_User = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.Username == Identity_User); var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == Identity_User);
if (user == null) return NotFound(); if (user == null) return NotFound();
// Anzeigedaten // Anzeigedaten
@@ -39,7 +40,7 @@ public class UserController : Controller
ViewBag.Name = username; ViewBag.Name = username;
ViewBag.Mail = mail; ViewBag.Mail = mail;
ViewBag.Id = Id; ViewBag.Id = Id;
return View(); return View();
} }
@@ -47,10 +48,10 @@ public class UserController : Controller
// Edit-Form anzeigen // Edit-Form anzeigen
[Authorize] [Authorize]
[HttpGet] [HttpGet]
public IActionResult Edit() public async Task<IActionResult> Edit()
{ {
var username = User.Identity?.Name; var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.Username == username); var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
@@ -65,12 +66,12 @@ public class UserController : Controller
[Authorize] [Authorize]
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public IActionResult Edit(EditUserViewModel model) public async Task<IActionResult> Edit(EditUserViewModel model)
{ {
if (!ModelState.IsValid) return View(model); if (!ModelState.IsValid) return View(model);
var username = User.Identity?.Name; var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.Username == username); var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
user.Username = model.Username; user.Username = model.Username;
@@ -80,7 +81,7 @@ public class UserController : Controller
user.Password = BCrypt.Net.BCrypt.HashPassword(model.NewPassword); user.Password = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
} }
_context.SaveChanges(); await _context.SaveChangesAsync();
// Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert // Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert
@@ -93,12 +94,12 @@ public class UserController : Controller
[Authorize] [Authorize]
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public IActionResult UserSettings(EditUserViewModel model) public async Task<IActionResult> UserSettings(EditUserViewModel model)
{ {
if (!ModelState.IsValid) return View(model); if (!ModelState.IsValid) return View(model);
var username = User.Identity?.Name; var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.Username == username); var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);
if (user == null) return NotFound(); if (user == null) return NotFound();
var databaseProvider = _context.Database.ProviderName; var databaseProvider = _context.Database.ProviderName;
@@ -108,10 +109,10 @@ public class UserController : Controller
// Passwort ändern // Passwort ändern
if (!string.IsNullOrWhiteSpace(model.NewPassword)) if (!string.IsNullOrWhiteSpace(model.NewPassword))
{ {
user.Username = BCrypt.Net.BCrypt.HashPassword(model.NewPassword); user.Password = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
} }
_context.SaveChanges(); await _context.SaveChangesAsync();
// Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert // Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert

View File

@@ -41,5 +41,19 @@ public class AppDbContext : DbContext
optionsBuilder.UseSqlite(connStr); optionsBuilder.UseSqlite(connStr);
} }
} }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Server IDs bei 0 starten lassen (statt Standard 1)
modelBuilder.Entity<Server>()
.Property(s => s.Id)
.ValueGeneratedOnAdd();
// SQLite-spezifische Konfiguration: AUTOINCREMENT startet bei 0
modelBuilder.Entity<Server>()
.ToTable(tb => tb.HasCheckConstraint("CK_Server_Id", "Id >= 0"));
}
} }

View File

@@ -0,0 +1,392 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Watcher.Data;
#nullable disable
namespace Watcher.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20251116233330_RenameServerPropertiesToPascalCase")]
partial class RenameServerPropertiesToPascalCase
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ContainerId")
.HasColumnType("TEXT")
.HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<string>("Image")
.HasColumnType("TEXT")
.HasAnnotation("Relational:JsonPropertyName", "image");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<bool>("IsRunning")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT")
.HasAnnotation("Relational:JsonPropertyName", "name");
b.Property<int>("ServerId")
.HasColumnType("INTEGER")
.HasAnnotation("Relational:JsonPropertyName", "Server_id");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("ServerId");
b.HasIndex("TagId");
b.ToTable("Containers");
});
modelBuilder.Entity("Watcher.Models.ContainerMetric", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double>("CPU_Load")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<int?>("ContainerId")
.HasColumnType("INTEGER");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ContainerMetrics");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Tag")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Images");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("ContainerId")
.HasColumnType("INTEGER");
b.Property<string>("Level")
.HasColumnType("TEXT");
b.Property<string>("Message")
.HasColumnType("TEXT");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ContainerId");
b.HasIndex("ServerId");
b.ToTable("LogEvents");
});
modelBuilder.Entity("Watcher.Models.Metric", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double>("CPU_Load")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Size")
.HasColumnType("REAL");
b.Property<double>("DISK_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Usage")
.HasColumnType("REAL");
b.Property<double>("GPU_Load")
.HasColumnType("REAL");
b.Property<double>("GPU_Temp")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Size")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Usage")
.HasColumnType("REAL");
b.Property<double>("NET_In")
.HasColumnType("REAL");
b.Property<double>("NET_Out")
.HasColumnType("REAL");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Metrics");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CpuCores")
.HasColumnType("INTEGER");
b.Property<double>("CpuLoadCritical")
.HasColumnType("REAL");
b.Property<double>("CpuLoadWarning")
.HasColumnType("REAL");
b.Property<double>("CpuTempCritical")
.HasColumnType("REAL");
b.Property<double>("CpuTempWarning")
.HasColumnType("REAL");
b.Property<string>("CpuType")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DiskSpace")
.HasColumnType("TEXT");
b.Property<double>("DiskTempCritical")
.HasColumnType("REAL");
b.Property<double>("DiskTempWarning")
.HasColumnType("REAL");
b.Property<double>("DiskUsageCritical")
.HasColumnType("REAL");
b.Property<double>("DiskUsageWarning")
.HasColumnType("REAL");
b.Property<double>("GpuLoadCritical")
.HasColumnType("REAL");
b.Property<double>("GpuLoadWarning")
.HasColumnType("REAL");
b.Property<double>("GpuTempCritical")
.HasColumnType("REAL");
b.Property<double>("GpuTempWarning")
.HasColumnType("REAL");
b.Property<string>("GpuType")
.HasColumnType("TEXT");
b.Property<string>("IPAddress")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsOnline")
.HasColumnType("INTEGER");
b.Property<bool>("IsVerified")
.HasColumnType("INTEGER");
b.Property<DateTime>("LastSeen")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<double>("RamLoadCritical")
.HasColumnType("REAL");
b.Property<double>("RamLoadWarning")
.HasColumnType("REAL");
b.Property<double>("RamSize")
.HasColumnType("REAL");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TagId");
b.ToTable("Servers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Tags");
});
modelBuilder.Entity("Watcher.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<DateTime>("LastLogin")
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.HasOne("Watcher.Models.Image", null)
.WithMany("Containers")
.HasForeignKey("ImageId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Containers")
.HasForeignKey("TagId");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.HasOne("Watcher.Models.Container", "Container")
.WithMany()
.HasForeignKey("ContainerId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.Navigation("Container");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Servers")
.HasForeignKey("TagId");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Navigation("Containers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Navigation("Containers");
b.Navigation("Servers");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,158 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Watcher.Migrations
{
/// <inheritdoc />
public partial class RenameServerPropertiesToPascalCase : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "RAM_Load_Warning",
table: "Servers",
newName: "RamLoadWarning");
migrationBuilder.RenameColumn(
name: "RAM_Load_Critical",
table: "Servers",
newName: "RamLoadCritical");
migrationBuilder.RenameColumn(
name: "GPU_Temp_Warning",
table: "Servers",
newName: "GpuTempWarning");
migrationBuilder.RenameColumn(
name: "GPU_Temp_Critical",
table: "Servers",
newName: "GpuTempCritical");
migrationBuilder.RenameColumn(
name: "GPU_Load_Warning",
table: "Servers",
newName: "GpuLoadWarning");
migrationBuilder.RenameColumn(
name: "GPU_Load_Critical",
table: "Servers",
newName: "GpuLoadCritical");
migrationBuilder.RenameColumn(
name: "Disk_Usage_Warning",
table: "Servers",
newName: "DiskUsageWarning");
migrationBuilder.RenameColumn(
name: "Disk_Usage_Critical",
table: "Servers",
newName: "DiskUsageCritical");
migrationBuilder.RenameColumn(
name: "DISK_Temp_Warning",
table: "Servers",
newName: "DiskTempWarning");
migrationBuilder.RenameColumn(
name: "DISK_Temp_Critical",
table: "Servers",
newName: "DiskTempCritical");
migrationBuilder.RenameColumn(
name: "CPU_Temp_Warning",
table: "Servers",
newName: "CpuTempWarning");
migrationBuilder.RenameColumn(
name: "CPU_Temp_Critical",
table: "Servers",
newName: "CpuTempCritical");
migrationBuilder.RenameColumn(
name: "CPU_Load_Warning",
table: "Servers",
newName: "CpuLoadWarning");
migrationBuilder.RenameColumn(
name: "CPU_Load_Critical",
table: "Servers",
newName: "CpuLoadCritical");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "RamLoadWarning",
table: "Servers",
newName: "RAM_Load_Warning");
migrationBuilder.RenameColumn(
name: "RamLoadCritical",
table: "Servers",
newName: "RAM_Load_Critical");
migrationBuilder.RenameColumn(
name: "GpuTempWarning",
table: "Servers",
newName: "GPU_Temp_Warning");
migrationBuilder.RenameColumn(
name: "GpuTempCritical",
table: "Servers",
newName: "GPU_Temp_Critical");
migrationBuilder.RenameColumn(
name: "GpuLoadWarning",
table: "Servers",
newName: "GPU_Load_Warning");
migrationBuilder.RenameColumn(
name: "GpuLoadCritical",
table: "Servers",
newName: "GPU_Load_Critical");
migrationBuilder.RenameColumn(
name: "DiskUsageWarning",
table: "Servers",
newName: "Disk_Usage_Warning");
migrationBuilder.RenameColumn(
name: "DiskUsageCritical",
table: "Servers",
newName: "Disk_Usage_Critical");
migrationBuilder.RenameColumn(
name: "DiskTempWarning",
table: "Servers",
newName: "DISK_Temp_Warning");
migrationBuilder.RenameColumn(
name: "DiskTempCritical",
table: "Servers",
newName: "DISK_Temp_Critical");
migrationBuilder.RenameColumn(
name: "CpuTempWarning",
table: "Servers",
newName: "CPU_Temp_Warning");
migrationBuilder.RenameColumn(
name: "CpuTempCritical",
table: "Servers",
newName: "CPU_Temp_Critical");
migrationBuilder.RenameColumn(
name: "CpuLoadWarning",
table: "Servers",
newName: "CPU_Load_Warning");
migrationBuilder.RenameColumn(
name: "CpuLoadCritical",
table: "Servers",
newName: "CPU_Load_Critical");
}
}
}

View File

@@ -0,0 +1,395 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Watcher.Data;
#nullable disable
namespace Watcher.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20251117142850_StartServerIdsAtZero")]
partial class StartServerIdsAtZero
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ContainerId")
.HasColumnType("TEXT")
.HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<string>("Image")
.HasColumnType("TEXT")
.HasAnnotation("Relational:JsonPropertyName", "image");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<bool>("IsRunning")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT")
.HasAnnotation("Relational:JsonPropertyName", "name");
b.Property<int>("ServerId")
.HasColumnType("INTEGER")
.HasAnnotation("Relational:JsonPropertyName", "Server_id");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("ServerId");
b.HasIndex("TagId");
b.ToTable("Containers");
});
modelBuilder.Entity("Watcher.Models.ContainerMetric", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double>("CPU_Load")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<int?>("ContainerId")
.HasColumnType("INTEGER");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ContainerMetrics");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Tag")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Images");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("ContainerId")
.HasColumnType("INTEGER");
b.Property<string>("Level")
.HasColumnType("TEXT");
b.Property<string>("Message")
.HasColumnType("TEXT");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ContainerId");
b.HasIndex("ServerId");
b.ToTable("LogEvents");
});
modelBuilder.Entity("Watcher.Models.Metric", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double>("CPU_Load")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Size")
.HasColumnType("REAL");
b.Property<double>("DISK_Temp")
.HasColumnType("REAL");
b.Property<double>("DISK_Usage")
.HasColumnType("REAL");
b.Property<double>("GPU_Load")
.HasColumnType("REAL");
b.Property<double>("GPU_Temp")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Size")
.HasColumnType("REAL");
b.Property<double>("GPU_Vram_Usage")
.HasColumnType("REAL");
b.Property<double>("NET_In")
.HasColumnType("REAL");
b.Property<double>("NET_Out")
.HasColumnType("REAL");
b.Property<double>("RAM_Load")
.HasColumnType("REAL");
b.Property<double>("RAM_Size")
.HasColumnType("REAL");
b.Property<int?>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Metrics");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CpuCores")
.HasColumnType("INTEGER");
b.Property<double>("CpuLoadCritical")
.HasColumnType("REAL");
b.Property<double>("CpuLoadWarning")
.HasColumnType("REAL");
b.Property<double>("CpuTempCritical")
.HasColumnType("REAL");
b.Property<double>("CpuTempWarning")
.HasColumnType("REAL");
b.Property<string>("CpuType")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DiskSpace")
.HasColumnType("TEXT");
b.Property<double>("DiskTempCritical")
.HasColumnType("REAL");
b.Property<double>("DiskTempWarning")
.HasColumnType("REAL");
b.Property<double>("DiskUsageCritical")
.HasColumnType("REAL");
b.Property<double>("DiskUsageWarning")
.HasColumnType("REAL");
b.Property<double>("GpuLoadCritical")
.HasColumnType("REAL");
b.Property<double>("GpuLoadWarning")
.HasColumnType("REAL");
b.Property<double>("GpuTempCritical")
.HasColumnType("REAL");
b.Property<double>("GpuTempWarning")
.HasColumnType("REAL");
b.Property<string>("GpuType")
.HasColumnType("TEXT");
b.Property<string>("IPAddress")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsOnline")
.HasColumnType("INTEGER");
b.Property<bool>("IsVerified")
.HasColumnType("INTEGER");
b.Property<DateTime>("LastSeen")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<double>("RamLoadCritical")
.HasColumnType("REAL");
b.Property<double>("RamLoadWarning")
.HasColumnType("REAL");
b.Property<double>("RamSize")
.HasColumnType("REAL");
b.Property<int?>("TagId")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TagId");
b.ToTable("Servers", t =>
{
t.HasCheckConstraint("CK_Server_Id", "Id >= 0");
});
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Tags");
});
modelBuilder.Entity("Watcher.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<DateTime>("LastLogin")
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Watcher.Models.Container", b =>
{
b.HasOne("Watcher.Models.Image", null)
.WithMany("Containers")
.HasForeignKey("ImageId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Containers")
.HasForeignKey("TagId");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
{
b.HasOne("Watcher.Models.Container", "Container")
.WithMany()
.HasForeignKey("ContainerId");
b.HasOne("Watcher.Models.Server", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.Navigation("Container");
b.Navigation("Server");
});
modelBuilder.Entity("Watcher.Models.Server", b =>
{
b.HasOne("Watcher.Models.Tag", null)
.WithMany("Servers")
.HasForeignKey("TagId");
});
modelBuilder.Entity("Watcher.Models.Image", b =>
{
b.Navigation("Containers");
});
modelBuilder.Entity("Watcher.Models.Tag", b =>
{
b.Navigation("Containers");
b.Navigation("Servers");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,43 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Watcher.Migrations
{
/// <inheritdoc />
public partial class StartServerIdsAtZero : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddCheckConstraint(
name: "CK_Server_Id",
table: "Servers",
sql: "Id >= 0");
// Bestehende Server-IDs um 1 verringern (1 -> 0, 2 -> 1, etc.)
migrationBuilder.Sql(@"
-- Bestehende Server-IDs anpassen, falls Server existieren
UPDATE Servers SET Id = Id - 1 WHERE EXISTS (SELECT 1 FROM Servers);
UPDATE Metrics SET ServerId = ServerId - 1 WHERE ServerId IS NOT NULL;
UPDATE Containers SET ServerId = ServerId - 1 WHERE ServerId IS NOT NULL;
-- sqlite_sequence anpassen oder initialisieren
-- Falls Eintrag existiert: seq - 1, ansonsten: INSERT mit seq = -1
-- Der nächste AUTOINCREMENT wird dann 0 sein
INSERT OR REPLACE INTO sqlite_sequence (name, seq)
VALUES ('Servers',
COALESCE((SELECT seq - 1 FROM sqlite_sequence WHERE name = 'Servers'), -1)
);
");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropCheckConstraint(
name: "CK_Server_Id",
table: "Servers");
}
}
}

View File

@@ -197,55 +197,55 @@ namespace Watcher.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<double>("CPU_Load_Critical")
.HasColumnType("REAL");
b.Property<double>("CPU_Load_Warning")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp_Critical")
.HasColumnType("REAL");
b.Property<double>("CPU_Temp_Warning")
.HasColumnType("REAL");
b.Property<int>("CpuCores") b.Property<int>("CpuCores")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<double>("CpuLoadCritical")
.HasColumnType("REAL");
b.Property<double>("CpuLoadWarning")
.HasColumnType("REAL");
b.Property<double>("CpuTempCritical")
.HasColumnType("REAL");
b.Property<double>("CpuTempWarning")
.HasColumnType("REAL");
b.Property<string>("CpuType") b.Property<string>("CpuType")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<double>("DISK_Temp_Critical")
.HasColumnType("REAL");
b.Property<double>("DISK_Temp_Warning")
.HasColumnType("REAL");
b.Property<string>("Description") b.Property<string>("Description")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("DiskSpace") b.Property<string>("DiskSpace")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<double>("Disk_Usage_Critical") b.Property<double>("DiskTempCritical")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("Disk_Usage_Warning") b.Property<double>("DiskTempWarning")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("GPU_Load_Critical") b.Property<double>("DiskUsageCritical")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("GPU_Load_Warning") b.Property<double>("DiskUsageWarning")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("GPU_Temp_Critical") b.Property<double>("GpuLoadCritical")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("GPU_Temp_Warning") b.Property<double>("GpuLoadWarning")
.HasColumnType("REAL");
b.Property<double>("GpuTempCritical")
.HasColumnType("REAL");
b.Property<double>("GpuTempWarning")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<string>("GpuType") b.Property<string>("GpuType")
@@ -268,10 +268,10 @@ namespace Watcher.Migrations
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<double>("RAM_Load_Critical") b.Property<double>("RamLoadCritical")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("RAM_Load_Warning") b.Property<double>("RamLoadWarning")
.HasColumnType("REAL"); .HasColumnType("REAL");
b.Property<double>("RamSize") b.Property<double>("RamSize")
@@ -288,7 +288,10 @@ namespace Watcher.Migrations
b.HasIndex("TagId"); b.HasIndex("TagId");
b.ToTable("Servers"); b.ToTable("Servers", t =>
{
t.HasCheckConstraint("CK_Server_Id", "Id >= 0");
});
}); });
modelBuilder.Entity("Watcher.Models.Tag", b => modelBuilder.Entity("Watcher.Models.Tag", b =>

View File

@@ -13,15 +13,15 @@ public class Container
public Server Server { get; set; } = null!; public Server Server { get; set; } = null!;
[JsonPropertyName("id")] [JsonPropertyName("id")]
public String? ContainerId { get; set; } public string? ContainerId { get; set; }
[JsonPropertyName("image")] [JsonPropertyName("image")]
public String? Image { get; set; } public string? Image { get; set; }
[JsonPropertyName("name")] [JsonPropertyName("name")]
public String? Name { get; set; } public string? Name { get; set; }
// keine Variable, die vom Agent übergeben wird. Ein container ist immer Running, die Variable dient nur für die Übersicht // keine Variable, die vom Agent übergeben wird. Ein container ist immer Running, die Variable dient nur für die Übersicht
// auf dem Dashboard. // auf dem Dashboard.
public Boolean IsRunning { get; set; } = true; public bool IsRunning { get; set; } = true;
} }

View File

@@ -29,32 +29,32 @@ public class Server
// Hardware Measurment Warning/Crit Values // Hardware Measurment Warning/Crit Values
public double CPU_Load_Warning { get; set; } = 75.0; public double CpuLoadWarning { get; set; } = 75.0;
public double CPU_Load_Critical { get; set; } = 90.0; public double CpuLoadCritical { get; set; } = 90.0;
public double CPU_Temp_Warning { get; set; } = 80.0; public double CpuTempWarning { get; set; } = 80.0;
public double CPU_Temp_Critical { get; set; } = 90.0; public double CpuTempCritical { get; set; } = 90.0;
public double RAM_Load_Warning { get; set; } = 85.0; public double RamLoadWarning { get; set; } = 85.0;
public double RAM_Load_Critical { get; set; } = 95.0; public double RamLoadCritical { get; set; } = 95.0;
public double GPU_Load_Warning { get; set; } = 75.0; public double GpuLoadWarning { get; set; } = 75.0;
public double GPU_Load_Critical { get; set; } = 90.0; public double GpuLoadCritical { get; set; } = 90.0;
public double GPU_Temp_Warning { get; set; } = 70.0; public double GpuTempWarning { get; set; } = 70.0;
public double GPU_Temp_Critical { get; set; } = 80.0; public double GpuTempCritical { get; set; } = 80.0;
public double Disk_Usage_Warning { get; set; } = 75.0; public double DiskUsageWarning { get; set; } = 75.0;
public double Disk_Usage_Critical { get; set; } = 90.0; public double DiskUsageCritical { get; set; } = 90.0;
public double DISK_Temp_Warning { get; set; } = 34.0; public double DiskTempWarning { get; set; } = 34.0;
public double DISK_Temp_Critical { get; set; } = 36.0; public double DiskTempCritical { get; set; } = 36.0;
// Database // Database
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public Boolean IsOnline { get; set; } = false; public bool IsOnline { get; set; } = false;
public DateTime LastSeen { get; set; } public DateTime LastSeen { get; set; }
public Boolean IsVerified { get; set; } = false; public bool IsVerified { get; set; } = false;
} }

View File

@@ -29,15 +29,33 @@ builder.Host.UseSerilog();
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
// Health Checks
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>("database");
// HttpContentAccessor // HttpContentAccessor
builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpContextAccessor();
// Storage Singleton // Storage Singleton
builder.Services.AddSingleton<IDashboardStore, DashboardStore>(); builder.Services.AddSingleton<IDashboardStore, DashboardStore>();
builder.Services.AddSingleton<ISystemStore, SystemStore>();
builder.Services.AddSingleton<IVersionService, VersionService>(); builder.Services.AddSingleton<IVersionService, VersionService>();
builder.Services.AddSingleton<IUpdateCheckStore, UpdateCheckStore>(); builder.Services.AddSingleton<IUpdateCheckStore, UpdateCheckStore>();
// SystemStore mit Konfiguration initialisieren
builder.Services.AddSingleton<ISystemStore>(sp =>
{
var configuration = sp.GetRequiredService<IConfiguration>();
var refreshIntervalSeconds = int.TryParse(
configuration["Frontend:RefreshIntervalSeconds"]
?? Environment.GetEnvironmentVariable("FRONTEND_REFRESH_INTERVAL_SECONDS"),
out var seconds) ? seconds : 30;
return new SystemStore
{
FrontendRefreshIntervalMilliseconds = refreshIntervalSeconds * 1000
};
});
// Background Services // Background Services
builder.Services.AddHostedService<NetworkCheck>(); builder.Services.AddHostedService<NetworkCheck>();
builder.Services.AddHostedService<DatabaseCheck>(); builder.Services.AddHostedService<DatabaseCheck>();
@@ -145,6 +163,9 @@ app.UseSwaggerUI(options =>
options.RoutePrefix = "api/v1/swagger"; options.RoutePrefix = "api/v1/swagger";
}); });
// 🔹 Health Check Endpoint
app.MapHealthChecks("/health");
// 🔹 Authentifizierung & Autorisierung // 🔹 Authentifizierung & Autorisierung
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@@ -2,7 +2,7 @@ namespace Watcher.Services;
public class DashboardStore : IDashboardStore public class DashboardStore : IDashboardStore
{ {
public String? NetworkStatus { get; set; } public string? NetworkStatus { get; set; }
public String? DatabaseStatus { get; set; } public string? DatabaseStatus { get; set; }
} }

View File

@@ -21,14 +21,14 @@ public class DatabaseCheck : BackgroundService
while (await timer.WaitForNextTickAsync(stoppingToken)) while (await timer.WaitForNextTickAsync(stoppingToken))
{ {
// Hintergrundprozess abwarten // Hintergrundprozess abwarten
await checkDatabaseIntegrity(); await CheckDatabaseIntegrity();
// 5 Sekdunden Offset // 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
} }
} }
// String sqliteConnectionString als Argument übergeben // String sqliteConnectionString als Argument übergeben
public Task checkDatabaseIntegrity() public Task CheckDatabaseIntegrity()
{ {
using var conn = new SqliteConnection("Data Source=./persistence/watcher.db"); using var conn = new SqliteConnection("Data Source=./persistence/watcher.db");
_logger.LogInformation("Sqlite Integrity-Check started..."); _logger.LogInformation("Sqlite Integrity-Check started...");

View File

@@ -2,6 +2,6 @@ namespace Watcher.Services;
public interface IDashboardStore public interface IDashboardStore
{ {
String? NetworkStatus { get; set; } string? NetworkStatus { get; set; }
String? DatabaseStatus { get; set; } string? DatabaseStatus { get; set; }
} }

View File

@@ -2,8 +2,10 @@ namespace Watcher.Services;
public interface ISystemStore public interface ISystemStore
{ {
Boolean NewVersionAvailable { get; set; } bool NewVersionAvailable { get; set; }
Double DatabaseSize { get; set; } double DatabaseSize { get; set; }
int FrontendRefreshIntervalMilliseconds { get; set; }
} }

View File

@@ -5,12 +5,12 @@ public class NetworkCheck : BackgroundService
{ {
private readonly ILogger<NetworkCheck> _logger; private readonly ILogger<NetworkCheck> _logger;
private IDashboardStore _DashboardStore; private IDashboardStore _dashboardStore;
public NetworkCheck(ILogger<NetworkCheck> logger, IDashboardStore DashboardStore) public NetworkCheck(ILogger<NetworkCheck> logger, IDashboardStore dashboardStore)
{ {
_logger = logger; _logger = logger;
_DashboardStore = DashboardStore; _dashboardStore = dashboardStore;
} }
@@ -21,14 +21,14 @@ public class NetworkCheck : BackgroundService
while (await timer.WaitForNextTickAsync(stoppingToken)) while (await timer.WaitForNextTickAsync(stoppingToken))
{ {
// Hintergrundprozess abwarten // Hintergrundprozess abwarten
await checkConnectionAsync(); await CheckConnectionAsync();
// 5 Sekdunden Offset // 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
} }
} }
public Task checkConnectionAsync() public Task CheckConnectionAsync()
{ {
_logger.LogInformation("Networkcheck started."); _logger.LogInformation("Networkcheck started.");
@@ -40,13 +40,13 @@ public class NetworkCheck : BackgroundService
PingReply reply = p.Send(host, 3000); PingReply reply = p.Send(host, 3000);
if (reply.Status == IPStatus.Success) if (reply.Status == IPStatus.Success)
{ {
_DashboardStore.NetworkStatus = "online"; _dashboardStore.NetworkStatus = "online";
_logger.LogInformation("Ping successfull. Watcher is online."); _logger.LogInformation("Ping successfull. Watcher is online.");
} }
} }
catch catch
{ {
_DashboardStore.NetworkStatus = "offline"; _dashboardStore.NetworkStatus = "offline";
_logger.LogError("Ping failed. Watcher appears to have no network connection."); _logger.LogError("Ping failed. Watcher appears to have no network connection.");
// LogEvent erstellen // LogEvent erstellen

View File

@@ -6,12 +6,12 @@ public class SystemManagement : BackgroundService
{ {
private readonly ILogger<NetworkCheck> _logger; private readonly ILogger<NetworkCheck> _logger;
private ISystemStore _SystemStore; private ISystemStore _systemStore;
public SystemManagement(ILogger<NetworkCheck> logger, ISystemStore SystemStore) public SystemManagement(ILogger<NetworkCheck> logger, ISystemStore systemStore)
{ {
_logger = logger; _logger = logger;
_SystemStore = SystemStore; _systemStore = systemStore;
} }
@@ -23,19 +23,19 @@ public class SystemManagement : BackgroundService
while (await timer.WaitForNextTickAsync(stoppingToken)) while (await timer.WaitForNextTickAsync(stoppingToken))
{ {
// Hintergrundprozess abwarten // Hintergrundprozess abwarten
await checkForNewDockerImageVersion(); await CheckForNewDockerImageVersion();
// 5 Sekdunden Offset // 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
} }
} }
public Task checkForNewDockerImageVersion() public Task CheckForNewDockerImageVersion()
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task createDailySqliteBackup() public Task CreateDailySqliteBackup()
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@@ -2,8 +2,10 @@ namespace Watcher.Services;
public class SystemStore: ISystemStore public class SystemStore: ISystemStore
{ {
public Boolean NewVersionAvailable { get; set; } public bool NewVersionAvailable { get; set; }
public Double DatabaseSize { get; set; } public double DatabaseSize { get; set; }
public int FrontendRefreshIntervalMilliseconds { get; set; }
} }

View File

@@ -14,8 +14,10 @@ namespace Watcher.ViewModels
public List<LogEvent> RecentEvents { get; set; } = new(); public List<LogEvent> RecentEvents { get; set; } = new();
public List<Container> Containers { get; set; } = new(); public List<Container> Containers { get; set; } = new();
public String? NetworkStatus { get; set; } = "?"; public string? NetworkStatus { get; set; } = "?";
public String? DatabaseStatus { get; set; } = "?"; public string? DatabaseStatus { get; set; } = "?";
public int RefreshIntervalMilliseconds { get; set; } = 30000;
} }
} }

View File

@@ -7,32 +7,32 @@ namespace Watcher.ViewModels
public int Id { get; set; } public int Id { get; set; }
[Required(ErrorMessage = "Name ist erforderlich")] [Required(ErrorMessage = "Name ist erforderlich")]
public string? Name { get; set; } public required string Name { get; set; }
[Required(ErrorMessage = "IP-Adresse ist erforderlich")] [Required(ErrorMessage = "IP-Adresse ist erforderlich")]
[RegularExpression(@"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", ErrorMessage = "Ungültige IP-Adresse")] [RegularExpression(@"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", ErrorMessage = "Ungültige IP-Adresse")]
public required string IPAddress { get; set; } public required string IPAddress { get; set; }
[Required(ErrorMessage = "Typ ist erforderlich")] [Required(ErrorMessage = "Typ ist erforderlich")]
public string? Type { get; set; } public required string Type { get; set; }
// Hardware Measurment Warning/Crit Values // Hardware Measurment Warning/Crit Values
public double CPU_Load_Warning { get; set; } = 75.0; public double CpuLoadWarning { get; set; } = 75.0;
public double CPU_Load_Critical { get; set; } = 90.0; public double CpuLoadCritical { get; set; } = 90.0;
public double CPU_Temp_Warning { get; set; } = 80.0; public double CpuTempWarning { get; set; } = 80.0;
public double CPU_Temp_Critical { get; set; } = 90.0; public double CpuTempCritical { get; set; } = 90.0;
public double RAM_Load_Warning { get; set; } = 85.0; public double RamLoadWarning { get; set; } = 85.0;
public double RAM_Load_Critical { get; set; } = 95.0; public double RamLoadCritical { get; set; } = 95.0;
public double GPU_Load_Warning { get; set; } = 75.0; public double GpuLoadWarning { get; set; } = 75.0;
public double GPU_Load_Critical { get; set; } = 90.0; public double GpuLoadCritical { get; set; } = 90.0;
public double GPU_Temp_Warning { get; set; } = 70.0; public double GpuTempWarning { get; set; } = 70.0;
public double GPU_Temp_Critical { get; set; } = 80.0; public double GpuTempCritical { get; set; } = 80.0;
public double Disk_Usage_Warning { get; set; } = 75.0; public double DiskUsageWarning { get; set; } = 75.0;
public double Disk_Usage_Critical { get; set; } = 90.0; public double DiskUsageCritical { get; set; } = 90.0;
public double DISK_Temp_Warning { get; set; } = 34.0; public double DiskTempWarning { get; set; } = 34.0;
public double DISK_Temp_Critical { get; set; } = 36.0; public double DiskTempCritical { get; set; } = 36.0;
} }
} }

View File

@@ -5,7 +5,7 @@ namespace Watcher.ViewModels;
public class EditUserViewModel public class EditUserViewModel
{ {
[Required] [Required]
public string? Username { get; set; } public required string Username { get; set; }
[Required] [Required]
[DataType(DataType.Password)] [DataType(DataType.Password)]

View File

@@ -31,9 +31,11 @@ public class ServerDetailsViewModel
// Database // Database
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public Boolean IsOnline { get; set; } = false; public bool IsOnline { get; set; } = false;
public DateTime LastSeen { get; set; } public DateTime LastSeen { get; set; }
public Boolean IsVerified { get; set; } = false; public bool IsVerified { get; set; } = false;
public int RefreshIntervalMilliseconds { get; set; } = 30000;
} }

View File

@@ -6,5 +6,6 @@ namespace Watcher.ViewModels
public class ServerOverviewViewModel public class ServerOverviewViewModel
{ {
public List<Server> Servers { get; set; } = new(); public List<Server> Servers { get; set; } = new();
public int RefreshIntervalMilliseconds { get; set; } = 30000;
} }
} }

View File

@@ -27,7 +27,7 @@
foreach (var serverGroup in groupedContainers.OrderBy(g => g.Key)) foreach (var serverGroup in groupedContainers.OrderBy(g => g.Key))
{ {
<div class="mb-4"> <div class="mb-4">
<h5 class="text-muted mb-3"> <h5 class="text-text mb-3">
<i class="bi bi-hdd-network me-2"></i>@serverGroup.Key <i class="bi bi-hdd-network me-2"></i>@serverGroup.Key
<span class="badge bg-secondary ms-2">@serverGroup.Count()</span> <span class="badge bg-secondary ms-2">@serverGroup.Count()</span>
</h5> </h5>

View File

@@ -31,8 +31,8 @@
} }
} }
// Initial laden und dann alle 30 Sekunden // Initial laden und dann mit konfiguriertem Intervall
loadDashboardStats(); loadDashboardStats();
setInterval(loadDashboardStats, 30000); setInterval(loadDashboardStats, @Model.RefreshIntervalMilliseconds);
</script> </script>
} }

View File

@@ -480,10 +480,10 @@
loadRamData(); loadRamData();
loadGpuData(); loadGpuData();
// Alle 30 Sekunden aktualisieren // Mit konfiguriertem Intervall aktualisieren
setInterval(loadCpuData, 30000); setInterval(loadCpuData, @Model.RefreshIntervalMilliseconds);
setInterval(loadRamData, 30000); setInterval(loadRamData, @Model.RefreshIntervalMilliseconds);
setInterval(loadGpuData, 30000); setInterval(loadGpuData, @Model.RefreshIntervalMilliseconds);
}); });
</script> </script>
} }

View File

@@ -54,32 +54,32 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="CPU_Load_Warning" class="form-label"><i class="bi bi-graph-up me-1"></i>Warnung bei Auslastung (%)</label> <label asp-for="CpuLoadWarning" class="form-label"><i class="bi bi-graph-up me-1"></i>Warnung bei Auslastung (%)</label>
<input asp-for="CPU_Load_Warning" class="form-control" placeholder="z.B. 80" /> <input asp-for="CpuLoadWarning" class="form-control" placeholder="z.B. 80" />
<span asp-validation-for="CPU_Load_Warning" class="text-danger small"></span> <span asp-validation-for="CpuLoadWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="CPU_Load_Critical" class="form-label"><i class="bi bi-graph-up me-1"></i>Kritische Auslastung (%)</label> <label asp-for="CpuLoadCritical" class="form-label"><i class="bi bi-graph-up me-1"></i>Kritische Auslastung (%)</label>
<input asp-for="CPU_Load_Critical" class="form-control" placeholder="z.B. 95" /> <input asp-for="CpuLoadCritical" class="form-control" placeholder="z.B. 95" />
<span asp-validation-for="CPU_Load_Critical" class="text-danger small"></span> <span asp-validation-for="CpuLoadCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="CPU_Temp_Warning" class="form-label"><i class="bi bi-thermometer-half me-1"></i>Warnung bei Temperatur (°C)</label> <label asp-for="CpuTempWarning" class="form-label"><i class="bi bi-thermometer-half me-1"></i>Warnung bei Temperatur (°C)</label>
<input asp-for="CPU_Temp_Warning" class="form-control" placeholder="z.B. 75" /> <input asp-for="CpuTempWarning" class="form-control" placeholder="z.B. 75" />
<span asp-validation-for="CPU_Temp_Warning" class="text-danger small"></span> <span asp-validation-for="CpuTempWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="CPU_Temp_Critical" class="form-label"><i class="bi bi-thermometer-high me-1"></i>Kritische Temperatur (°C)</label> <label asp-for="CpuTempCritical" class="form-label"><i class="bi bi-thermometer-high me-1"></i>Kritische Temperatur (°C)</label>
<input asp-for="CPU_Temp_Critical" class="form-control" placeholder="z.B. 90" /> <input asp-for="CpuTempCritical" class="form-control" placeholder="z.B. 90" />
<span asp-validation-for="CPU_Temp_Critical" class="text-danger small"></span> <span asp-validation-for="CpuTempCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>
@@ -90,16 +90,16 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="RAM_Load_Warning" class="form-label"><i class="bi bi-graph-up me-1"></i>Warnung bei Auslastung (%)</label> <label asp-for="RamLoadWarning" class="form-label"><i class="bi bi-graph-up me-1"></i>Warnung bei Auslastung (%)</label>
<input asp-for="RAM_Load_Warning" class="form-control" placeholder="z.B. 85" /> <input asp-for="RamLoadWarning" class="form-control" placeholder="z.B. 85" />
<span asp-validation-for="RAM_Load_Warning" class="text-danger small"></span> <span asp-validation-for="RamLoadWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="RAM_Load_Critical" class="form-label"><i class="bi bi-graph-up me-1"></i>Kritische Auslastung (%)</label> <label asp-for="RamLoadCritical" class="form-label"><i class="bi bi-graph-up me-1"></i>Kritische Auslastung (%)</label>
<input asp-for="RAM_Load_Critical" class="form-control" placeholder="z.B. 98" /> <input asp-for="RamLoadCritical" class="form-control" placeholder="z.B. 98" />
<span asp-validation-for="RAM_Load_Critical" class="text-danger small"></span> <span asp-validation-for="RamLoadCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>
@@ -110,32 +110,32 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="Disk_Usage_Warning" class="form-label"><i class="bi bi-disc-fill me-1"></i>Warnung bei Auslastung (%)</label> <label asp-for="DiskUsageWarning" class="form-label"><i class="bi bi-disc-fill me-1"></i>Warnung bei Auslastung (%)</label>
<input asp-for="Disk_Usage_Warning" class="form-control" placeholder="z.B. 90" /> <input asp-for="DiskUsageWarning" class="form-control" placeholder="z.B. 90" />
<span asp-validation-for="Disk_Usage_Warning" class="text-danger small"></span> <span asp-validation-for="DiskUsageWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="Disk_Usage_Critical" class="form-label"><i class="bi bi-disc-fill me-1"></i>Kritische Auslastung (%)</label> <label asp-for="DiskUsageCritical" class="form-label"><i class="bi bi-disc-fill me-1"></i>Kritische Auslastung (%)</label>
<input asp-for="Disk_Usage_Critical" class="form-control" placeholder="z.B. 98" /> <input asp-for="DiskUsageCritical" class="form-control" placeholder="z.B. 98" />
<span asp-validation-for="Disk_Usage_Critical" class="text-danger small"></span> <span asp-validation-for="DiskUsageCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="DISK_Temp_Warning" class="form-label"><i class="bi bi-thermometer-half me-1"></i>Warnung bei Temperatur (°C)</label> <label asp-for="DiskTempWarning" class="form-label"><i class="bi bi-thermometer-half me-1"></i>Warnung bei Temperatur (°C)</label>
<input asp-for="DISK_Temp_Warning" class="form-control" placeholder="z.B. 45" /> <input asp-for="DiskTempWarning" class="form-control" placeholder="z.B. 45" />
<span asp-validation-for="DISK_Temp_Warning" class="text-danger small"></span> <span asp-validation-for="DiskTempWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="DISK_Temp_Critical" class="form-label"><i class="bi bi-thermometer-high me-1"></i>Kritische Temperatur (°C)</label> <label asp-for="DiskTempCritical" class="form-label"><i class="bi bi-thermometer-high me-1"></i>Kritische Temperatur (°C)</label>
<input asp-for="DISK_Temp_Critical" class="form-control" placeholder="z.B. 55" /> <input asp-for="DiskTempCritical" class="form-control" placeholder="z.B. 55" />
<span asp-validation-for="DISK_Temp_Critical" class="text-danger small"></span> <span asp-validation-for="DiskTempCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>
@@ -146,32 +146,32 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="GPU_Load_Warning" class="form-label"><i class="bi bi-graph-up me-1"></i>Warnung bei Auslastung (%)</label> <label asp-for="GpuLoadWarning" class="form-label"><i class="bi bi-graph-up me-1"></i>Warnung bei Auslastung (%)</label>
<input asp-for="GPU_Load_Warning" class="form-control" placeholder="z.B. 80" /> <input asp-for="GpuLoadWarning" class="form-control" placeholder="z.B. 80" />
<span asp-validation-for="GPU_Load_Warning" class="text-danger small"></span> <span asp-validation-for="GpuLoadWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="GPU_Load_Critical" class="form-label"><i class="bi bi-graph-up me-1"></i>Kritische Auslastung (%)</label> <label asp-for="GpuLoadCritical" class="form-label"><i class="bi bi-graph-up me-1"></i>Kritische Auslastung (%)</label>
<input asp-for="GPU_Load_Critical" class="form-control" placeholder="z.B. 95" /> <input asp-for="GpuLoadCritical" class="form-control" placeholder="z.B. 95" />
<span asp-validation-for="GPU_Load_Critical" class="text-danger small"></span> <span asp-validation-for="GpuLoadCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="GPU_Temp_Warning" class="form-label"><i class="bi bi-thermometer-half me-1"></i>Warnung bei Temperatur (°C)</label> <label asp-for="GpuTempWarning" class="form-label"><i class="bi bi-thermometer-half me-1"></i>Warnung bei Temperatur (°C)</label>
<input asp-for="GPU_Temp_Warning" class="form-control" placeholder="z.B. 70" /> <input asp-for="GpuTempWarning" class="form-control" placeholder="z.B. 70" />
<span asp-validation-for="GPU_Temp_Warning" class="text-danger small"></span> <span asp-validation-for="GpuTempWarning" class="text-danger small"></span>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<label asp-for="GPU_Temp_Critical" class="form-label"><i class="bi bi-thermometer-high me-1"></i>Kritische Temperatur (°C)</label> <label asp-for="GpuTempCritical" class="form-label"><i class="bi bi-thermometer-high me-1"></i>Kritische Temperatur (°C)</label>
<input asp-for="GPU_Temp_Critical" class="form-control" placeholder="z.B. 85" /> <input asp-for="GpuTempCritical" class="form-control" placeholder="z.B. 85" />
<span asp-validation-for="GPU_Temp_Critical" class="text-danger small"></span> <span asp-validation-for="GpuTempCritical" class="text-danger small"></span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -125,45 +125,65 @@
// Lade aktuelle Metriken für alle Server // Lade aktuelle Metriken für alle Server
async function loadCurrentMetrics() { async function loadCurrentMetrics() {
const metricElements = document.querySelectorAll('.metric-value'); // Sammle alle eindeutigen Server-IDs
const serverIds = new Set();
for (const element of metricElements) { document.querySelectorAll('.metric-value').forEach(el => {
const serverId = element.getAttribute('data-server-id'); const serverId = el.getAttribute('data-server-id');
const metricType = element.getAttribute('data-metric'); if (serverId) serverIds.add(serverId);
});
// Lade Metriken für jeden Server
for (const serverId of serverIds) {
try { try {
let endpoint = ''; const response = await fetch(`/monitoring/current-metrics/${serverId}`);
if (metricType === 'cpu') endpoint = `/monitoring/cpu-usage?serverId=${serverId}&hours=0.1`;
else if (metricType === 'ram') endpoint = `/monitoring/ram-usage?serverId=${serverId}&hours=0.1`;
else if (metricType === 'gpu') endpoint = `/monitoring/gpu-usage?serverId=${serverId}&hours=0.1`;
const response = await fetch(endpoint);
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
if (data && data.length > 0) {
const latestValue = data[data.length - 1].data;
element.textContent = `${latestValue.toFixed(1)}%`;
// Update progress bar if (data.hasData) {
const card = element.closest('.card'); // Update CPU
let barClass = ''; updateMetric(serverId, 'cpu', data.cpu, '.server-cpu-bar', 'bg-info');
if (metricType === 'cpu') barClass = '.server-cpu-bar';
else if (metricType === 'ram') barClass = '.server-ram-bar';
else if (metricType === 'gpu') barClass = '.server-gpu-bar';
const bar = card.querySelector(barClass); // Update RAM
if (bar) { updateMetric(serverId, 'ram', data.ram, '.server-ram-bar', 'bg-success');
bar.style.width = `${latestValue}%`;
} // Update GPU (falls vorhanden)
updateMetric(serverId, 'gpu', data.gpu, '.server-gpu-bar', 'bg-danger');
} }
} }
} catch (err) { } catch (err) {
console.error(`Fehler beim Laden der ${metricType}-Metriken für Server ${serverId}:`, err); console.error(`Fehler beim Laden der Metriken für Server ${serverId}:`, err);
} }
} }
} }
// Initial laden und alle 30 Sekunden aktualisieren function updateMetric(serverId, metricType, value, barClass, defaultColorClass) {
// Finde das Element für diesen Server und Metrik-Typ
const metricElement = document.querySelector(`.metric-value[data-server-id="${serverId}"][data-metric="${metricType}"]`);
if (!metricElement) return;
// Update Text
metricElement.textContent = `${value.toFixed(1)}%`;
// Update Progress Bar
const card = metricElement.closest('.card');
const bar = card.querySelector(barClass);
if (bar) {
bar.style.width = `${value}%`;
// Optional: Farbe basierend auf Wert ändern
bar.className = 'progress-bar';
if (value >= 90) {
bar.classList.add('bg-danger');
} else if (value >= 75) {
bar.classList.add('bg-warning');
} else {
bar.classList.add(defaultColorClass);
}
}
}
// Initial laden und mit konfiguriertem Intervall aktualisieren
loadCurrentMetrics(); loadCurrentMetrics();
setInterval(loadCurrentMetrics, 30000); const refreshInterval = @(ViewBag.RefreshIntervalMilliseconds ?? 30000);
setInterval(loadCurrentMetrics, refreshInterval);
</script> </script>

View File

@@ -44,8 +44,8 @@
} }
} }
// Initial laden und dann alle 30 Sekunden // Initial laden und dann mit konfiguriertem Intervall
loadServerCards(); loadServerCards();
setInterval(loadServerCards, 30000); setInterval(loadServerCards, @Model.RefreshIntervalMilliseconds);
</script> </script>
} }

View File

@@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.8" /> <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.8" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.3.0" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" /> <PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />

View File

@@ -12,5 +12,9 @@
"ConnectionStrings": { "ConnectionStrings": {
"Sqlite": "Data Source=./persistence/watcher.db" "Sqlite": "Data Source=./persistence/watcher.db"
} }
},
"Frontend": {
"RefreshIntervalSeconds": 30
} }
} }

View File

@@ -1,27 +1,66 @@
services: services:
watcher: watcher:
image: git.triggermeelmo.com/watcher/watcher-server:${IMAGE_VERSION:-latest} image: git.triggermeelmo.com/watcher/watcher-server:latest
container_name: watcher container_name: watcher
# Resource Management
deploy: deploy:
resources: resources:
limits: limits:
memory: 200M memory: 200M
cpus: '0.5'
restart: unless-stopped restart: unless-stopped
env_file: .env
# Security - User/Group ID aus Umgebungsvariablen
user: "${USER_UID:-1000}:${USER_GID:-1000}"
# Health Check
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Environment
environment: environment:
# Application Version (wird aus Image-Tag übernommen) # Non-Root User
- WATCHER_VERSION=${IMAGE_VERSION:-latest} - USER_UID=1000 # Standard 1000
- USER_GID=1000 # Standard 1000
# Timezone
- TZ=Europe/Berlin
# Update Check # Update Check
- UPDATE_CHECK_ENABLED=true - UPDATE_CHECK_ENABLED=true
- UPDATE_CHECK_INTERVAL_HOURS=24 - UPDATE_CHECK_INTERVAL_HOURS=24
- UPDATE_CHECK_REPOSITORY_URL=https://git.triggermeelmo.com/api/v1/repos/Watcher/watcher/releases/latest - UPDATE_CHECK_REPOSITORY_URL=https://git.triggermeelmo.com/api/v1/repos/Watcher/watcher/releases/latest
# Data Retention Policy # Data Retention Policy
- METRIC_RETENTION_DAYS=30 - METRIC_RETENTION_DAYS=30
- METRIC_CLEANUP_INTERVAL_HOURS=24 - METRIC_CLEANUP_INTERVAL_HOURS=24
- METRIC_CLEANUP_ENABLED=true - METRIC_CLEANUP_ENABLED=true
# Aktualisierungsrate Frontend
- FRONTEND_REFRESH_INTERVAL_SECONDS=30
# Ports
ports: ports:
- "5000:5000" - "5000:5000"
# Volumes
volumes: volumes:
- ./watcher-volumes/data:/app/persistence - ./data/db:/app/persistence
- ./watcher-volumes/dumps:/app/wwwroot/downloads/sqlite - ./data/dumps:/app/wwwroot/downloads/sqlite
- ./watcher-volumes/logs:/app/logs - ./data/logs:/app/logs
# Labels (Traefik Integration)
labels:
- "traefik.enable=true"
- "traefik.http.routers.watcher.rule=Host(`watcher.example.com`)"
- "traefik.http.routers.watcher.entrypoints=websecure"
- "traefik.http.routers.watcher.tls.certresolver=letsencrypt"
- "traefik.http.services.watcher.loadbalancer.server.port=5000"
- "com.watcher.description=Server Monitoring Application"
- "com.watcher.version=${IMAGE_VERSION:-latest}"