Compare commits
2 Commits
b8b0520eaa
...
v0.1.13
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e8bfaee45 | |||
| 42a40e8b2e |
@@ -3,9 +3,39 @@ import urllib.request
|
||||
|
||||
url = "http://localhost:5000/monitoring/service-discovery"
|
||||
payload = {
|
||||
"server_id": 7,
|
||||
"containers": ["{\"id\":\"6621c5b67c25\",\"image\":\"git.triggermeelmo.com/donpat1to/watcher-agent:v0.1.26\",\"name\":\"watcher-agent\"}",
|
||||
"{\"id\":\"b8c86fb260bd\",\"image\":\"git.triggermeelmo.com/watcher/watcher-server:v0.1.10\",\"name\":\"watcher\"}"]
|
||||
"Server_id": 2,
|
||||
"Containers": [
|
||||
{
|
||||
"id": "3e74abf5ce30",
|
||||
"image": "hello-world:latest",
|
||||
"name": "serene_nightingale"
|
||||
},
|
||||
{
|
||||
"id": "83cd9d461690",
|
||||
"image": "postgres:latest",
|
||||
"name": "distracted_feistel"
|
||||
},
|
||||
{
|
||||
"id": "b296c2ed1213",
|
||||
"image": "postgres:latest",
|
||||
"name": "mystifying_jackson"
|
||||
},
|
||||
{
|
||||
"id": "69568181d576",
|
||||
"image": "hello-world:latest",
|
||||
"name": "romantic_driscoll"
|
||||
},
|
||||
{
|
||||
"id": "67c37a2b1791",
|
||||
"image": "hello-world:latest",
|
||||
"name": "asdf"
|
||||
},
|
||||
{
|
||||
"id": "8f39bae1e316",
|
||||
"image": "hello-world:latest",
|
||||
"name": "distracted_mirzakhani"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
|
||||
@@ -82,10 +82,15 @@ public class MetricDto
|
||||
public double NET_Out { get; set; } // Bytes/s
|
||||
}
|
||||
|
||||
public class ServiceDto
|
||||
public class DockerServiceDto
|
||||
{
|
||||
public required int server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
||||
public required List<String> containers { get; set; }
|
||||
public required int Server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
||||
public required JsonElement Containers { get; set; }
|
||||
}
|
||||
|
||||
public class DockerServiceMetricDto
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
@@ -226,7 +231,7 @@ public class MonitoringController : Controller
|
||||
|
||||
// Endpoint, an dem Agents Ihre laufenden Services registrieren
|
||||
[HttpPost("service-discovery")]
|
||||
public async Task<IActionResult> ServiceDetection([FromBody] ServiceDto dto)
|
||||
public async Task<IActionResult> ServiceDetection([FromBody] DockerServiceDto dto)
|
||||
{
|
||||
// Gültigkeit des Payloads prüfen
|
||||
if (!ModelState.IsValid)
|
||||
@@ -240,38 +245,13 @@ public class MonitoringController : Controller
|
||||
return BadRequest(new { error = "Invalid Payload", details = errors });
|
||||
}
|
||||
|
||||
// Json zu was brauchbarem machen
|
||||
//string containersJson = await dto.containers.ReadAsStringAsync();
|
||||
//List<Container> newContainers = JsonSerializer.Deserialize<List<Container>>(containersJson)?? new List<Container>();;
|
||||
|
||||
List<Container> newContainers = new List<Container>();
|
||||
|
||||
foreach (String s in dto.containers)
|
||||
{
|
||||
// JSON zu einem JsonDocument parsen
|
||||
using JsonDocument doc = JsonDocument.Parse(s);
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
// Einzelne Werte extrahieren
|
||||
string id = root.GetProperty("id").GetString() ?? "";
|
||||
string image = root.GetProperty("image").GetString() ?? "";
|
||||
string name = root.GetProperty("name").GetString() ?? "";
|
||||
|
||||
Container newContainer = new Container
|
||||
{
|
||||
ServerId = dto.server_id,
|
||||
ContainerId = id,
|
||||
Image = image,
|
||||
Name = name,
|
||||
};
|
||||
|
||||
|
||||
newContainers.Add(newContainer);
|
||||
}
|
||||
List<Container> newContainers =
|
||||
JsonSerializer.Deserialize<List<Container>>(dto.Containers.GetRawText())
|
||||
?? new List<Container>();
|
||||
|
||||
foreach (Container c in newContainers)
|
||||
{
|
||||
c.ServerId = dto.server_id;
|
||||
c.ServerId = dto.Server_id;
|
||||
// Debug Logs
|
||||
// TODO entfernen wenn fertig getestet
|
||||
Console.WriteLine("---------");
|
||||
@@ -283,12 +263,9 @@ public class MonitoringController : Controller
|
||||
|
||||
}
|
||||
|
||||
// Container Objekte erstellen
|
||||
//List<Container> newContainers = ParseServiceDiscoveryInput(dto.Server_id, containers);
|
||||
|
||||
// Liste aller Container, die bereits der übergebenen ServerId zugewiesen sind
|
||||
List<Container> existingContainers = _context.Containers
|
||||
.Where(c => c.ServerId == dto.server_id)
|
||||
.Where(c => c.ServerId == dto.Server_id)
|
||||
.ToList();
|
||||
|
||||
|
||||
@@ -339,7 +316,7 @@ public class MonitoringController : Controller
|
||||
}
|
||||
|
||||
// Endpoint, an den der Agent die Metrics der registrierten Container schickt
|
||||
/*public async Task<IActionResult> ServiceMetrics([FromBody] ServiceMetricDto dto)
|
||||
public async Task<IActionResult> ServiceMetrics([FromBody] DockerServiceMetricDto dto)
|
||||
{
|
||||
// Gültigkeit des Payloads prüfen
|
||||
if (!ModelState.IsValid)
|
||||
@@ -375,7 +352,7 @@ public class MonitoringController : Controller
|
||||
|
||||
return Ok();
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
// Durchschnittliche Werte Berechnen
|
||||
public async Task<IActionResult> CalculateMedian(string Metric, int HoursToMonitor, int ServerId)
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace Watcher.Models;
|
||||
|
||||
public class Container
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("Server_id")]
|
||||
public int ServerId { get; set; }
|
||||
|
||||
[JsonPropertyName("id")]
|
||||
public String? ContainerId { get; set; }
|
||||
|
||||
[JsonPropertyName("image")]
|
||||
|
||||
Reference in New Issue
Block a user