aa
This commit is contained in:
@@ -8,6 +8,7 @@ using watcher_monitoring.Models;
|
|||||||
using watcher_monitoring.Data;
|
using watcher_monitoring.Data;
|
||||||
using watcher_monitoring.Attributes;
|
using watcher_monitoring.Attributes;
|
||||||
using watcher_monitoring.Payloads;
|
using watcher_monitoring.Payloads;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ public class APIController : Controller
|
|||||||
public async Task<IActionResult> Containers()
|
public async Task<IActionResult> Containers()
|
||||||
{
|
{
|
||||||
List<Container> containers = await _context.Containers.ToListAsync();
|
List<Container> containers = await _context.Containers.ToListAsync();
|
||||||
return Ok();
|
return Ok(containers);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("delete-container")]
|
[HttpDelete("delete-container")]
|
||||||
@@ -166,15 +167,18 @@ public class APIController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Server server = new Server
|
Server newServer = new Server
|
||||||
{
|
{
|
||||||
Name = "test",
|
Name = dto.hostName,
|
||||||
IPAddress = dto.IpAddress
|
IPAddress = dto.ipAddress
|
||||||
};
|
};
|
||||||
|
|
||||||
_context.Servers.Add(server);
|
_context.Servers.Add(newServer);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return Ok();
|
|
||||||
|
var server = await _context.Servers.FindAsync(dto.ipAddress);
|
||||||
|
|
||||||
|
return Ok(server.Id);
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
@@ -201,7 +205,7 @@ public class APIController : Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Find Server in Database
|
// Find Server in Database
|
||||||
var server = await _context.Servers.FindAsync(dto.Id);
|
var server = await _context.Servers.FindAsync(dto.id);
|
||||||
|
|
||||||
if (server == null)
|
if (server == null)
|
||||||
{
|
{
|
||||||
@@ -210,11 +214,11 @@ public class APIController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add Hardware Configuration
|
// Add Hardware Configuration
|
||||||
server.CpuType = dto.CpuType;
|
server.CpuType = dto.cpuType;
|
||||||
server.CpuCores = dto.CpuCores;
|
server.CpuCores = dto.cpuCores;
|
||||||
server.GpuType = dto.GpuType;
|
server.GpuType = dto.gpuType;
|
||||||
server.RamSize = dto.RamSize;
|
server.RamSize = dto.ramSize;
|
||||||
// Diskspace fehlt
|
// TODO: Diskspace fehlt
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
_logger.LogInformation("Harware configuration successfull for server {server}", server.Name);
|
_logger.LogInformation("Harware configuration successfull for server {server}", server.Name);
|
||||||
@@ -231,9 +235,34 @@ public class APIController : Controller
|
|||||||
|
|
||||||
// Server-Metrics endpoint for watcher-agent
|
// Server-Metrics endpoint for watcher-agent
|
||||||
[HttpPost("agent-server-metrics/{id}")]
|
[HttpPost("agent-server-metrics/{id}")]
|
||||||
public async Task<IActionResult> ServerMetrics ([FromBody] HardwareDto dto)
|
public async Task<IActionResult> ServerMetrics ([FromBody] MetricDto dto)
|
||||||
{
|
{
|
||||||
return Ok();
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = ModelState.Values
|
||||||
|
.SelectMany(v => v.Errors)
|
||||||
|
.Select(e => e.ErrorMessage)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_logger.LogError("Invalid monitoring payload");
|
||||||
|
return BadRequest(new { error = "Invalid monitoring payload", details = errors });
|
||||||
|
}
|
||||||
|
|
||||||
|
var server = await _context.Servers.FindAsync(dto.id);
|
||||||
|
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
// neues Objekt mit Typ Metric anlegen
|
||||||
|
|
||||||
|
// Metric in Datenbank eintragen
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogError("metric cannot be added to database");
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service-Detection endpoint for watcher-agent
|
// Service-Detection endpoint for watcher-agent
|
||||||
@@ -244,7 +273,7 @@ public class APIController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Container-Metrics endpoint for watcher-agent
|
// Container-Metrics endpoint for watcher-agent
|
||||||
[HttpPost("agent-container-metrics/{id}")]
|
[HttpPost("agent-container-metrics")]
|
||||||
public async Task<IActionResult> ContainerMetrics ([FromBody] HardwareDto dto)
|
public async Task<IActionResult> ContainerMetrics ([FromBody] HardwareDto dto)
|
||||||
{
|
{
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|||||||
@@ -6,21 +6,18 @@ namespace watcher_monitoring.Payloads;
|
|||||||
public class HardwareDto
|
public class HardwareDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public required int Id;
|
public required int id;
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string? IpAddress { get; set; }
|
|
||||||
|
|
||||||
// Hardware Info
|
// Hardware Info
|
||||||
[Required]
|
[Required]
|
||||||
public string? CpuType { get; set; }
|
public string? cpuType { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int CpuCores { get; set; }
|
public int cpuCores { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string? GpuType { get; set; }
|
public string? gpuType { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public double RamSize { get; set; }
|
public double ramSize { get; set; }
|
||||||
}
|
}
|
||||||
44
watcher-monitoring/Payloads/MetricDto.cs
Normal file
44
watcher-monitoring/Payloads/MetricDto.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Payloads;
|
||||||
|
|
||||||
|
public class MetricDto
|
||||||
|
{
|
||||||
|
// Server Identity
|
||||||
|
[Required]
|
||||||
|
public int id { get; set; }
|
||||||
|
|
||||||
|
// Hardware Metrics
|
||||||
|
// CPU
|
||||||
|
public double cpuLoad { get; set; } // %
|
||||||
|
|
||||||
|
public double cpuTemp { get; set; } // deg C
|
||||||
|
|
||||||
|
// GPU
|
||||||
|
public double gpuLoad { get; set; } // %
|
||||||
|
|
||||||
|
public double gpuTemp { get; set; } // deg C
|
||||||
|
|
||||||
|
public double vRamSize { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double vRamLoad { get; set; } // %
|
||||||
|
|
||||||
|
// RAM
|
||||||
|
public double ramSize { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double ramLoad { get; set; } // %
|
||||||
|
|
||||||
|
// Disks
|
||||||
|
public double diskSize { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double diskLoad { get; set; } // Bytes
|
||||||
|
|
||||||
|
public double diskTempp { get; set; } // deg C (if available)
|
||||||
|
|
||||||
|
// Network
|
||||||
|
public double netIn { get; set; } // Bytes/s
|
||||||
|
|
||||||
|
public double netOut { get; set; } // Bytes/s
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,5 +7,7 @@ namespace watcher_monitoring.Payloads;
|
|||||||
public class RegistrationDto
|
public class RegistrationDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public required string IpAddress { get; set; }
|
public required string ipAddress { get; set; }
|
||||||
|
|
||||||
|
public required string hostName { get; set; }
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
<li class="dropdown-item">
|
<li class="dropdown-item">
|
||||||
<a style="display: inline-block; vertical-align: middle; margin-right: 8px;">
|
<a style="display: inline-block; vertical-align: middle; margin-right: 8px;"
|
||||||
asp-area="" asp-controller="User" asp-action="Index"><svg width="16" height="16"
|
asp-area="" asp-controller="User" asp-action="Index"><svg width="16" height="16"
|
||||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||||
style="display: inline-block; vertical-align: middle; margin-right: 8px;">
|
style="display: inline-block; vertical-align: middle; margin-right: 8px;">
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user