From 5e2f9e4c3cc63b1e71b7a269363b0a10596cf0f4 Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Tue, 30 Sep 2025 12:21:25 +0200 Subject: [PATCH 1/3] sanitizeMetrics Funktion erstellt --- .readthedocs.yaml | 23 --------------------- Watcher/Controllers/MonitoringController.cs | 16 +++++++++++++- 2 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 .readthedocs.yaml diff --git a/.readthedocs.yaml b/.readthedocs.yaml deleted file mode 100644 index c4b4ce2..0000000 --- a/.readthedocs.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Read the Docs configuration file -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details - -# Required -version: 2 - -# Set the OS, Python version, and other tools you might need -build: - os: ubuntu-24.04 - tools: - python: "3.13" - -# Build documentation in the "docs/" directory with Sphinx -sphinx: - configuration: docs/conf.py - -# Optionally, but recommended, -# declare the Python requirements required to build your documentation -# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html -# python: -# install: -# - requirements: docs/requirements.txt - \ No newline at end of file diff --git a/Watcher/Controllers/MonitoringController.cs b/Watcher/Controllers/MonitoringController.cs index 3357bf2..0a922b1 100644 --- a/Watcher/Controllers/MonitoringController.cs +++ b/Watcher/Controllers/MonitoringController.cs @@ -183,7 +183,7 @@ public class MonitoringController : Controller GPU_Temp = dto.GPU_Temp, GPU_Vram_Size = dto.GPU_Vram_Size, GPU_Vram_Usage = dto.GPU_Vram_Usage, - RAM_Load = dto.RAM_Load, + RAM_Load = sanitizeByteInput(dto.RAM_Load), RAM_Size = dto.RAM_Size, DISK_Size = dto.RAM_Size, DISK_Usage = dto.DISK_Usage, @@ -281,4 +281,18 @@ public class MonitoringController : Controller return Ok(data); } + + // Metric Input Byte zu Gigabyte umwandeln + public static double sanitizeByteInput(double metric_input) + { + // *10^-9 um auf Gigabyte zu kommen + double sanitizedMetric = metric_input * Math.Pow(10, -9); + + // Auf 2 Nachkommastellen runden + Math.Round(sanitizedMetric, 2); + + return sanitizedMetric; + } + + // Metric Input Bit zu Gigabit umwandeln } \ No newline at end of file From 36e16fbcf96c43d1f366a4b96a65628afe84d97f Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Wed, 1 Oct 2025 12:52:45 +0200 Subject: [PATCH 2/3] =?UTF-8?q?sanitizemetrics=20eingef=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Watcher/Controllers/MonitoringController.cs | 28 +++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Watcher/Controllers/MonitoringController.cs b/Watcher/Controllers/MonitoringController.cs index 0a922b1..2dea5d9 100644 --- a/Watcher/Controllers/MonitoringController.cs +++ b/Watcher/Controllers/MonitoringController.cs @@ -55,26 +55,26 @@ public class MetricDto public double GPU_Temp { get; set; } // deg C - public double GPU_Vram_Size { get; set; } // GB + public double GPU_Vram_Size { get; set; } // Bytes public double GPU_Vram_Usage { get; set; } // % // RAM - public double RAM_Size { get; set; } // GB + public double RAM_Size { get; set; } // Bytes public double RAM_Load { get; set; } // % // Disks - public double DISK_Size { get; set; } // GB + public double DISK_Size { get; set; } // Bytes - public double DISK_Usage { get; set; } // % + public double DISK_Usage { get; set; } // Bytes - public double DISK_Temp { get; set; } // deg C + public double DISK_Temp { get; set; } // deg C (if available) // Network - public double NET_In { get; set; } // Bit + public double NET_In { get; set; } // Bytes/s - public double NET_Out { get; set; } // Bit + public double NET_Out { get; set; } // Bytes/s } @@ -173,6 +173,7 @@ public class MonitoringController : Controller if (server != null) { + // neues Metric-Objekt erstellen var NewMetric = new Metric { Timestamp = DateTime.UtcNow, @@ -181,18 +182,19 @@ public class MonitoringController : Controller CPU_Temp = dto.CPU_Temp, GPU_Load = dto.GPU_Load, GPU_Temp = dto.GPU_Temp, - GPU_Vram_Size = dto.GPU_Vram_Size, + GPU_Vram_Size = sanitizeByteInput(dto.GPU_Vram_Size), GPU_Vram_Usage = dto.GPU_Vram_Usage, RAM_Load = sanitizeByteInput(dto.RAM_Load), - RAM_Size = dto.RAM_Size, - DISK_Size = dto.RAM_Size, - DISK_Usage = dto.DISK_Usage, + RAM_Size = sanitizeByteInput(dto.RAM_Size), + DISK_Size = sanitizeByteInput(dto.DISK_Size), + DISK_Usage = sanitizeByteInput(dto.DISK_Usage), DISK_Temp = dto.DISK_Temp, - NET_In = dto.NET_In, - NET_Out = dto.NET_Out + NET_In = sanitizeByteInput(dto.NET_In), + NET_Out = sanitizeByteInput(dto.NET_Out) }; try { + // Metric Objekt in Datenbank einfügen _context.Metrics.Add(NewMetric); await _context.SaveChangesAsync(); From 85c5a803605283a416073fef0150645575e3b2df Mon Sep 17 00:00:00 2001 From: daniel-hbn Date: Wed, 1 Oct 2025 12:57:27 +0200 Subject: [PATCH 3/3] sanitizeDegreeInputs --- Watcher/Controllers/MonitoringController.cs | 30 +++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Watcher/Controllers/MonitoringController.cs b/Watcher/Controllers/MonitoringController.cs index 2dea5d9..ca18c92 100644 --- a/Watcher/Controllers/MonitoringController.cs +++ b/Watcher/Controllers/MonitoringController.cs @@ -178,17 +178,17 @@ public class MonitoringController : Controller { Timestamp = DateTime.UtcNow, ServerId = dto.ServerId, - CPU_Load = dto.CPU_Load, - CPU_Temp = dto.CPU_Temp, - GPU_Load = dto.GPU_Load, - GPU_Temp = dto.GPU_Temp, + CPU_Load = sanitizeLoadInput(dto.CPU_Load), + CPU_Temp = sanitizeDegreeInput(dto.CPU_Temp), + GPU_Load = sanitizeLoadInput(dto.GPU_Load), + GPU_Temp = sanitizeDegreeInput(dto.GPU_Temp), GPU_Vram_Size = sanitizeByteInput(dto.GPU_Vram_Size), - GPU_Vram_Usage = dto.GPU_Vram_Usage, + GPU_Vram_Usage = sanitizeLoadInput(dto.GPU_Vram_Usage), RAM_Load = sanitizeByteInput(dto.RAM_Load), RAM_Size = sanitizeByteInput(dto.RAM_Size), DISK_Size = sanitizeByteInput(dto.DISK_Size), DISK_Usage = sanitizeByteInput(dto.DISK_Usage), - DISK_Temp = dto.DISK_Temp, + DISK_Temp = sanitizeDegreeInput(dto.DISK_Temp), NET_In = sanitizeByteInput(dto.NET_In), NET_Out = sanitizeByteInput(dto.NET_Out) }; @@ -292,9 +292,23 @@ public class MonitoringController : Controller // Auf 2 Nachkommastellen runden Math.Round(sanitizedMetric, 2); - + return sanitizedMetric; } - // Metric Input Bit zu Gigabit umwandeln + // Degree Input auf zwei Nachkommastellen runden + public static double sanitizeDegreeInput(double metric_input) + { + Math.Round(metric_input, 2); + + return metric_input; + } + + // Load Input auf zwei Nachkommastellen runden + public static double sanitizeLoadInput(double metric_input) + { + Math.Round(metric_input, 2); + + return metric_input; + } } \ No newline at end of file