From ee5fe878020b9809a332a018532b5a62e2d00b03 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 7 Apr 2026 12:14:38 +0200 Subject: [PATCH] update con log x rimozione valori da redis se scritti sul DB --- MP.IOC/Services/MetricsDbFlushService.cs | 30 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/MP.IOC/Services/MetricsDbFlushService.cs b/MP.IOC/Services/MetricsDbFlushService.cs index 0c7b076f..f4595367 100644 --- a/MP.IOC/Services/MetricsDbFlushService.cs +++ b/MP.IOC/Services/MetricsDbFlushService.cs @@ -90,14 +90,17 @@ namespace MP.IOC.Services var avgDuration = totalMs / count; + var finalMaxMs = (maxMs == 0) ? avgDuration : maxMs; + var finalMinMs = (minMs == 0) ? avgDuration : minMs; + var aggrRecord = new StatsAggregatedModel { Hour = hourStart, Type = method, RequestCount = count, AvgDuration = avgDuration, - MaxDuration = maxMs, - MinDuration = minMs, + MaxDuration = finalMaxMs, + MinDuration = finalMinMs, NoReply = 0 }; @@ -112,6 +115,9 @@ namespace MP.IOC.Services if (detailCount == 0) continue; + var finalDetailMaxMs = (detailMaxMs == 0) ? (detailTotalMs / detailCount) : detailMaxMs; + var finalDetailMinMs = (detailMinMs == 0) ? (detailTotalMs / detailCount) : detailMinMs; + var detailRecord = new StatsDetailModel { Environment = destStat.Key, @@ -119,8 +125,8 @@ namespace MP.IOC.Services Hour = hourStart, RequestCount = detailCount, AvgDuration = detailTotalMs / detailCount, - MaxDuration = detailMaxMs, - MinDuration = detailMinMs, + MaxDuration = finalDetailMaxMs, + MinDuration = finalDetailMinMs, NoReply = 0 }; @@ -132,12 +138,28 @@ namespace MP.IOC.Services { await _aggrService.UpsertManyAsync(aggrRecords, false); Log.Info("Flushed {count} current aggregated stats records", aggrRecords.Count); + + var sampleCount = Math.Min(10, aggrRecords.Count); + for (int i = 0; i < sampleCount; i++) + { + var r = aggrRecords[i]; + Log.Info("[SAMPLE] INSERT Aggregated: Hour={hour}, Type={type}, Count={count}, Avg={avg:F2}ms, Min={min:F2}ms, Max={max:F2}ms", + r.Hour.ToString("yyyy-MM-dd HH:mm"), r.Type, r.RequestCount, r.AvgDuration, r.MinDuration, r.MaxDuration); + } } if (detailRecords.Count > 0) { await _detailService.UpsertManyAsync(detailRecords, false); Log.Info("Flushed {count} current detail stats records", detailRecords.Count); + + var sampleCount = Math.Min(10, detailRecords.Count); + for (int i = 0; i < sampleCount; i++) + { + var r = detailRecords[i]; + Log.Info("[SAMPLE] INSERT Detail: Env={env}, Type={type}, Hour={hour}, Count={count}, Avg={avg:F2}ms, Min={min:F2}ms, Max={max:F2}ms", + r.Environment, r.Type, r.Hour.ToString("yyyy-MM-dd HH:mm"), r.RequestCount, r.AvgDuration, r.MinDuration, r.MaxDuration); + } } _stats.Clear();