Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2c6071960 |
@@ -8,6 +8,7 @@ using watcher_monitoring.Models;
|
||||
using watcher_monitoring.Data;
|
||||
using watcher_monitoring.Attributes;
|
||||
using watcher_monitoring.Payloads;
|
||||
using System.Net;
|
||||
|
||||
|
||||
|
||||
@@ -122,7 +123,7 @@ public class APIController : Controller
|
||||
public async Task<IActionResult> Containers()
|
||||
{
|
||||
List<Container> containers = await _context.Containers.ToListAsync();
|
||||
return Ok();
|
||||
return Ok(containers);
|
||||
}
|
||||
|
||||
[HttpDelete("delete-container")]
|
||||
@@ -166,15 +167,18 @@ public class APIController : Controller
|
||||
}
|
||||
|
||||
try {
|
||||
Server server = new Server
|
||||
Server newServer = new Server
|
||||
{
|
||||
Name = "test",
|
||||
IPAddress = dto.IpAddress
|
||||
Name = dto.hostName,
|
||||
IPAddress = dto.ipAddress
|
||||
};
|
||||
|
||||
_context.Servers.Add(server);
|
||||
_context.Servers.Add(newServer);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok();
|
||||
|
||||
var server = await _context.Servers.FindAsync(dto.ipAddress);
|
||||
|
||||
return Ok(server.Id);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
@@ -201,7 +205,7 @@ public class APIController : Controller
|
||||
try
|
||||
{
|
||||
// Find Server in Database
|
||||
var server = await _context.Servers.FindAsync(dto.Id);
|
||||
var server = await _context.Servers.FindAsync(dto.id);
|
||||
|
||||
if (server == null)
|
||||
{
|
||||
@@ -210,11 +214,11 @@ public class APIController : Controller
|
||||
}
|
||||
|
||||
// Add Hardware Configuration
|
||||
server.CpuType = dto.CpuType;
|
||||
server.CpuCores = dto.CpuCores;
|
||||
server.GpuType = dto.GpuType;
|
||||
server.RamSize = dto.RamSize;
|
||||
// Diskspace fehlt
|
||||
server.CpuType = dto.cpuType;
|
||||
server.CpuCores = dto.cpuCores;
|
||||
server.GpuType = dto.gpuType;
|
||||
server.RamSize = dto.ramSize;
|
||||
// TODO: Diskspace fehlt
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
_logger.LogInformation("Harware configuration successfull for server {server}", server.Name);
|
||||
@@ -231,10 +235,35 @@ public class APIController : Controller
|
||||
|
||||
// Server-Metrics endpoint for watcher-agent
|
||||
[HttpPost("agent-server-metrics/{id}")]
|
||||
public async Task<IActionResult> ServerMetrics ([FromBody] HardwareDto dto)
|
||||
public async Task<IActionResult> ServerMetrics ([FromBody] MetricDto dto)
|
||||
{
|
||||
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
|
||||
[HttpPost("agent-container-detection")]
|
||||
@@ -244,7 +273,7 @@ public class APIController : Controller
|
||||
}
|
||||
|
||||
// Container-Metrics endpoint for watcher-agent
|
||||
[HttpPost("agent-container-metrics/{id}")]
|
||||
[HttpPost("agent-container-metrics")]
|
||||
public async Task<IActionResult> ContainerMetrics ([FromBody] HardwareDto dto)
|
||||
{
|
||||
return Ok();
|
||||
|
||||
@@ -6,21 +6,18 @@ namespace watcher_monitoring.Payloads;
|
||||
public class HardwareDto
|
||||
{
|
||||
[Required]
|
||||
public required int Id;
|
||||
|
||||
[Required]
|
||||
public string? IpAddress { get; set; }
|
||||
public required int id;
|
||||
|
||||
// Hardware Info
|
||||
[Required]
|
||||
public string? CpuType { get; set; }
|
||||
public string? cpuType { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CpuCores { get; set; }
|
||||
public int cpuCores { get; set; }
|
||||
|
||||
[Required]
|
||||
public string? GpuType { get; set; }
|
||||
public string? gpuType { get; set; }
|
||||
|
||||
[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
|
||||
{
|
||||
[Required]
|
||||
public required string IpAddress { get; set; }
|
||||
public required string ipAddress { get; set; }
|
||||
|
||||
public required string hostName { get; set; }
|
||||
}
|
||||
@@ -58,7 +58,7 @@
|
||||
</form>
|
||||
</li>
|
||||
<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"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
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