update con log x rimozione valori da redis se scritti sul DB

This commit is contained in:
Samuele E. Locatelli (W11-AI)
2026-04-07 12:14:38 +02:00
parent 6e9bad7247
commit ee5fe87802
+26 -4
View File
@@ -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();