Compare commits
2 Commits
f1287314f4
...
a6d992c874
| Author | SHA1 | Date | |
|---|---|---|---|
| a6d992c874 | |||
| 8475083897 |
@@ -18,17 +18,17 @@ public class ContainerController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> Overview()
|
public async Task<IActionResult> Overview()
|
||||||
{
|
|
||||||
var containers = await _context.Containers.ToListAsync();
|
|
||||||
var servers = await _context.Servers.ToListAsync();
|
|
||||||
|
|
||||||
var viewModel = new ContainerOverviewViewModel
|
|
||||||
{
|
{
|
||||||
Servers = servers,
|
var containers = await _context.Containers.ToListAsync();
|
||||||
Containers = containers
|
var servers = await _context.Servers.ToListAsync();
|
||||||
};
|
|
||||||
|
|
||||||
return View(viewModel);
|
var viewModel = new ContainerOverviewViewModel
|
||||||
}
|
{
|
||||||
|
Servers = servers,
|
||||||
|
Containers = containers
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Net.Http.Json;
|
using System.Net;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -85,7 +85,7 @@ public class MetricDto
|
|||||||
public class ServiceDto
|
public class ServiceDto
|
||||||
{
|
{
|
||||||
public required int server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
public required int server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
||||||
public required List<String> containers { get; set; }
|
public required List<Container> containers { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@@ -338,6 +338,45 @@ public class MonitoringController : Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Endpoint, an den der Agent die Metrics der registrierten Container schickt
|
||||||
|
public async Task<IActionResult> ServiceMetrics([FromBody] ServiceMetricDto dto)
|
||||||
|
{
|
||||||
|
// Gültigkeit des Payloads prüfen
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = ModelState.Values
|
||||||
|
.SelectMany(v => v.Errors)
|
||||||
|
.Select(e => e.ErrorMessage)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_logger.LogError("Invalid ServiceDetection-Payload.");
|
||||||
|
return BadRequest(new { error = "Invalid Payload", details = errors });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Liste an Metrics aus der dto erstellen
|
||||||
|
List<ContainerMetric> metrics = new List<ContainerMetric>();
|
||||||
|
|
||||||
|
// Metrics in die Datenbank eintragen
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (ContainerMetric m in metrics)
|
||||||
|
{
|
||||||
|
_context.ContainerMetrics.Add(m);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
// _logger.LogInformation(m. + " added for Host " + c.ServerId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SqliteException e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e.Message);
|
||||||
|
return StatusCode(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Durchschnittliche Werte Berechnen
|
// Durchschnittliche Werte Berechnen
|
||||||
public async Task<IActionResult> CalculateMedian(string Metric, int HoursToMonitor, int ServerId)
|
public async Task<IActionResult> CalculateMedian(string Metric, int HoursToMonitor, int ServerId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public class AppDbContext : DbContext
|
|||||||
|
|
||||||
public DbSet<Tag> Tags { get; set; }
|
public DbSet<Tag> Tags { get; set; }
|
||||||
|
|
||||||
|
public DbSet<ContainerMetric> ContainerMetrics { get; set; }
|
||||||
|
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
|||||||
355
Watcher/Migrations/20251029125404_ContainerMetrics-Added.Designer.cs
generated
Normal file
355
Watcher/Migrations/20251029125404_ContainerMetrics-Added.Designer.cs
generated
Normal file
@@ -0,0 +1,355 @@
|
|||||||
|
// <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("20251029125404_ContainerMetrics-Added")]
|
||||||
|
partial class ContainerMetricsAdded
|
||||||
|
{
|
||||||
|
/// <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");
|
||||||
|
|
||||||
|
b.Property<string>("Image")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int?>("ImageId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("IsRunning")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("ServerId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int?>("TagId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ImageId");
|
||||||
|
|
||||||
|
b.HasIndex("TagId");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
|
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<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")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("CpuType")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("DISK_Temp_Critical")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("DISK_Temp_Warning")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("DiskSpace")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("Disk_Usage_Critical")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("Disk_Usage_Warning")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("GPU_Load_Critical")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("GPU_Load_Warning")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("GPU_Temp_Critical")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("GPU_Temp_Warning")
|
||||||
|
.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>("RAM_Load_Critical")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("RAM_Load_Warning")
|
||||||
|
.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<string>("IdentityProvider")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastLogin")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("OIDC_Id")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.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.Tag", null)
|
||||||
|
.WithMany("Containers")
|
||||||
|
.HasForeignKey("TagId");
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Watcher/Migrations/20251029125404_ContainerMetrics-Added.cs
Normal file
22
Watcher/Migrations/20251029125404_ContainerMetrics-Added.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Watcher.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class ContainerMetricsAdded : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Watcher/Models/ContainerMetric.cs
Normal file
24
Watcher/Models/ContainerMetric.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
namespace Watcher.Models;
|
||||||
|
|
||||||
|
public class ContainerMetric
|
||||||
|
{
|
||||||
|
// Metric Metadata
|
||||||
|
public int Id { get; set; }
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
// Zuordnung zu einem Container -- Foreign Key
|
||||||
|
public int? ContainerId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
// CPU-Daten
|
||||||
|
public double CPU_Load { get; set; } = 0.0; // %
|
||||||
|
|
||||||
|
public double CPU_Temp { get; set; } = 0.0; // deg C
|
||||||
|
|
||||||
|
// RAM-Daten
|
||||||
|
public double RAM_Size { get; set; } = 0.0; // GB
|
||||||
|
|
||||||
|
public double RAM_Load { get; set; } = 0.0; // %
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user