Completato setup ottimizzato per RIOC

This commit is contained in:
Samuele Locatelli
2026-05-08 08:23:35 +02:00
parent f95e7c441b
commit 46f8377acb
3 changed files with 104 additions and 3 deletions
+100 -1
View File
@@ -1,6 +1,9 @@
@page
@* @page
@using MP.RIOC.Services
@inject RouteStatsManager StatsManager
@{
Layout = null;
var metrics = StatsManager.Snapshot();
}
<!DOCTYPE html>
<html>
@@ -22,4 +25,100 @@
<small>Versione Router: @System.Reflection.Assembly.GetExecutingAssembly().GetName().Version</small>
</div>
</body>
</html> *@
@page
@using MP.RIOC.Services
@inject RouteStatsManager StatsManager
@{
Layout = null;
var metrics = StatsManager.Snapshot();
}
<!DOCTYPE html>
<html>
<head>
<title>MP.RIOC Dashboard</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f2f5; padding: 30px; color: #333; }
.card { background: white; padding: 25px; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); max-width: 900px; margin: auto; }
h1 { color: #0056b3; margin-top: 0; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; }
th { background-color: #f8f9fa; color: #666; text-transform: uppercase; font-size: 0.85em; }
.tag { padding: 4px 8px; border-radius: 4px; font-size: 0.8em; font-weight: bold; }
.tag-ioc { background: #e3f2fd; color: #0d47a1; }
.tag-io { background: #fff3e0; color: #e65100; }
.latency { font-family: monospace; font-weight: bold; }
.d-flex { display: flex !important; }
.justify-content-between { justify-content: space-between !important; }
.align-items-center { align-items: center !important; }
.flex-column { flex-direction: column !important; }
.text-end { text-align: right !important; }
.px-0 { padding-left: 0 !important; padding-right: 0 !important; }
/* Miglioramento per l'intestazione custom */
.header-container {
border-bottom: 2px solid #0056b3;
margin-bottom: 20px;
padding-bottom: 10px;
}
h1 { margin: 0; font-size: 2.5em; color: #0056b3; line-height: 1; }
h2 { margin: 0; font-size: 1.8em; color: #333; line-height: 1; }
h3 { margin: 5px 0 0 0; font-size: 1em; color: #666; font-weight: normal; }
</style>
</head>
<body>
<div class="card">
<div class="d-flex justify-content-between align-items-center header-container">
<div class="px-0">
<h1>MAPO MES</h1>
<div>Live Dashboard</div>
</div>
<div class="px-0 text-end">
<h2>MP-RIOC</h2>
<h3>Router I/O Controller</h3>
</div>
</div>
<div class="d-flex justify-content-between align-items-center">
<div class="px-0">
Stato: <span style="color:green">● Online</span>
</div>
<div class="px-0 text-end">
Versione: @System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
</div>
</div>
<table>
<thead>
<tr>
<th>Target | Metodo | ID</th>
<th class="text-end">Chiamate</th>
<th class="text-end">Latenza Media</th>
</tr>
</thead>
<tbody>
@foreach (var stat in metrics)
{
<tr>
<td>
@if(stat.Key.StartsWith("IOC")) { <span class="tag tag-ioc">NEW</span> }
else { <span class="tag tag-io">OLD</span> }
@stat.Key
</td>
<td class="text-end">@stat.Value.Count</td>
<td class="latency text-end">@(stat.Value.AvgDuration)ms</td>
</tr>
}
@if (!metrics.Any())
{
<tr>
<td colspan="3" style="text-align:center; padding: 40px; color: #999;">Nessun dato raccolto al momento.</td>
</tr>
}
</tbody>
</table>
<div class="text-end" style="margin-top: 20px; font-size: 0.8em; color: #999;">
Ultimo aggiornamento: @DateTime.Now.ToString("HH:mm:ss")
</p>
</div>
</body>
</html>
+3 -2
View File
@@ -112,12 +112,13 @@ app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments(routePath, StringComparis
// 6. Definizione degli Endpoints locali
app.MapRazorPages();
app.MapGet("/router-status", () => Results.Ok(new
app.MapGet("/router-status", (RouteStatsManager stats) => Results.Ok(new
{
Status = "Online",
Version = assemblyVersion,
Mode = weightOnRedis ? "Redis" : "InMemory",
Time = DateTime.Now
Time = DateTime.Now,
Metrics = stats.Snapshot()
}));
// 7. Fallback "intelligente"
+1
View File
@@ -9,6 +9,7 @@ namespace MP.RIOC.Services
public TimeSpan MaxDuration = TimeSpan.Zero;
public TimeSpan MinDuration = TimeSpan.MaxValue;
public ConcurrentDictionary<int, long> StatusCodes = new();
public TimeSpan AvgDuration => TotalDuration / (Count > 0 ? Count : 1);
}
public class RouteStatsManager