201 lines
6.1 KiB
Plaintext
201 lines
6.1 KiB
Plaintext
@using EgwCoreLib.Lux.Core.Stats
|
|
@using EgwCoreLib.Lux.Data.Services
|
|
@using EgwCoreLib.Lux.Data.Services.General
|
|
@inject CalcRuidService Calc
|
|
@inject IJSRuntime JSRuntime
|
|
@implements IDisposable
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between">
|
|
<div class="px-0">
|
|
<h3>Statistiche in tempo reale</h3>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col">
|
|
<canvas id="chartRequestsMinute" width="400" height="180"></canvas>
|
|
</div>
|
|
<div class="col">
|
|
<canvas id="chartRequestsHour" width="400" height="180"></canvas>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col">
|
|
<canvas id="chartAvgProcessing" width="400" height="180"></canvas>
|
|
</div>
|
|
<div class="col">
|
|
<canvas id="chartMaxProcessing" width="400" height="180"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@code {
|
|
private StatsRealtimeDto? stats;
|
|
private CancellationTokenSource? _cts;
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await InitCharts();
|
|
_cts = new CancellationTokenSource();
|
|
_ = UpdateLoop(_cts.Token);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts?.Cancel();
|
|
_cts?.Dispose();
|
|
}
|
|
|
|
private async Task InitCharts()
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartRequestsMinute", new
|
|
{
|
|
type = "line",
|
|
data = new
|
|
{
|
|
labels = new[] { "Now" },
|
|
datasets = new[]
|
|
{
|
|
new {
|
|
label = "Richieste/minuto",
|
|
data = new[] { 0 },
|
|
borderColor = "blue"
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartRequestsHour", new
|
|
{
|
|
type = "bar",
|
|
data = new
|
|
{
|
|
labels = new[] { "Now" },
|
|
datasets = new[]
|
|
{
|
|
new {
|
|
label = "Richieste/ora",
|
|
data = new[] { 0 },
|
|
backgroundColor = "green"
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartAvgProcessing", new
|
|
{
|
|
type = "line",
|
|
data = new
|
|
{
|
|
labels = new[] { "Now" },
|
|
datasets = new[]
|
|
{
|
|
new {
|
|
label = "Tempo medio (s)",
|
|
data = new[] { 0 },
|
|
borderColor = "orange"
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartMaxProcessing", new
|
|
{
|
|
type = "line",
|
|
data = new
|
|
{
|
|
labels = new[] { "Now" },
|
|
datasets = new[]
|
|
{
|
|
new {
|
|
label = "Tempo massimo (s)",
|
|
data = new[] { 0 },
|
|
borderColor = "red"
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
// private async Task UpdateLoop(CancellationToken token)
|
|
// {
|
|
// var timer = new PeriodicTimer(TimeSpan.FromSeconds(5));
|
|
|
|
// try
|
|
// {
|
|
// while (await timer.WaitForNextTickAsync(token))
|
|
// {
|
|
// stats = await Calc.GetStatsAsync();
|
|
|
|
// await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
|
|
// "chartRequestsMinute",
|
|
// DateTime.Now.ToString("HH:mm:ss"),
|
|
// stats.RequestsLastMinute);
|
|
|
|
// await JSRuntime.InvokeVoidAsync("chartsInterop.updateBarChart",
|
|
// "chartRequestsHour",
|
|
// DateTime.Now.ToString("HH:mm:ss"),
|
|
// stats.RequestsLastHour);
|
|
|
|
// await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
|
|
// "chartAvgProcessing",
|
|
// DateTime.Now.ToString("HH:mm:ss"),
|
|
// stats.ProcessingAvgLastHour);
|
|
|
|
// await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
|
|
// "chartMaxProcessing",
|
|
// DateTime.Now.ToString("HH:mm:ss"),
|
|
// stats.ProcessingMaxLastHour);
|
|
|
|
// }
|
|
// }
|
|
// catch (OperationCanceledException)
|
|
// {
|
|
// // timer fermato
|
|
// }
|
|
// }
|
|
|
|
private async Task UpdateLoop(CancellationToken token)
|
|
{
|
|
try
|
|
{
|
|
while (!token.IsCancellationRequested)
|
|
{
|
|
stats = await Calc.GetStatsAsync();
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
|
|
"chartRequestsMinute",
|
|
DateTime.Now.ToString("HH:mm:ss"),
|
|
stats.RequestsLastMinute);
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.updateBarChart",
|
|
"chartRequestsHour",
|
|
DateTime.Now.ToString("HH:mm:ss"),
|
|
stats.RequestsLastHour);
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
|
|
"chartAvgProcessing",
|
|
DateTime.Now.ToString("HH:mm:ss"),
|
|
stats.ProcessingAvgLastHour);
|
|
|
|
await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
|
|
"chartMaxProcessing",
|
|
DateTime.Now.ToString("HH:mm:ss"),
|
|
stats.ProcessingMaxLastHour);
|
|
|
|
// attesa 5 secondi, rispettando il token
|
|
await Task.Delay(TimeSpan.FromSeconds(5), token);
|
|
}
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// loop fermato
|
|
}
|
|
}
|
|
|
|
|
|
}
|