Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions ThingConnect.Pulse.Server/Services/EndpointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public EndpointService(PulseDbContext context)
if (endpoint == null) return null;

var windowStart = DateTimeOffset.UtcNow.AddMinutes(-windowMinutes);
var windowStartUnix = windowStart.ToUnixTimeSeconds();

// --- Fetch recent raw checks ---
var rawChecks = await _context.CheckResultsRaw
.Where(c => c.EndpointId == id)
.Where(c => c.EndpointId == id && c.Ts >= windowStartUnix)
.OrderByDescending(c => c.Ts)
.Take(RecentFetchLimit)
.ToListAsync();
Expand All @@ -46,31 +47,21 @@ public EndpointService(PulseDbContext context)
RttMs = c.RttMs,
Error = c.Error
})
.Where(r => r.Ts >= windowStart)
.OrderByDescending(r => r.Ts)
.ToList();

// --- Fetch outages within window ---
var outageRaw = await _context.Outages
.Where(o => o.EndpointId == id)
.ToListAsync();

var outages = outageRaw
.Where(o =>
{
var started = ConvertToDateTimeOffset(o.StartedTs);
var ended = o.EndedTs != null ? ConvertToDateTimeOffset(o.EndedTs) : (DateTimeOffset?)null;
return started <= DateTimeOffset.UtcNow && (ended == null || ended >= windowStart);
})
.OrderByDescending(o => ConvertToDateTimeOffset(o.StartedTs))
var outages = await _context.Outages
.Where(o => o.EndpointId == id &&
o.StartedTs <= DateTimeOffset.UtcNow.ToUnixTimeSeconds() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we check the StartedTS to be less than the DateTimeOffset now this will always pass ?

(o.EndedTs == null || o.EndedTs >= windowStartUnix))
.OrderByDescending(o => o.StartedTs)
.Select(o => new OutageDto
{
StartedTs = ConvertToDateTimeOffset(o.StartedTs),
EndedTs = o.EndedTs != null ? ConvertToDateTimeOffset(o.EndedTs) : null,
DurationS = NormalizeDurationToInt(o.DurationSeconds),
LastError = o.LastError
})
.ToList();
.ToListAsync();

// --- Map endpoint DTO ---
var endpointDto = MapToEndpointDto(endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MonitoringBackgroundService(IServiceProvider serviceProvider,
_logger = logger;

// Read concurrency limit from configuration
_maxConcurrentProbes = configuration.GetValue<int>("Monitoring:MaxConcurrentProbes", 100);
_maxConcurrentProbes = configuration.GetValue<int>("Monitoring:MaxConcurrentProbes", 20);
_concurrencySemaphore = new SemaphoreSlim(_maxConcurrentProbes, _maxConcurrentProbes);

_logger.LogInformation("Monitoring service initialized with max concurrent probes: {MaxConcurrentProbes}",
Expand Down
2 changes: 1 addition & 1 deletion ThingConnect.Pulse.Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"ConfigPath": "C:\\ProgramData\\ThingConnect.Pulse\\config\\config.yaml",
"DataRetentionDays": 60,
"ProbeSettings": {
"MaxConcurrentProbes": 100,
"MaxConcurrentProbes": 20,
"TimeoutMs": 5000,
"RetryCount": 2,
"FlapDamping": {
Expand Down
4 changes: 2 additions & 2 deletions ThingConnect.Pulse.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"ConfigPath": "C:\\ProgramData\\ThingConnect.Pulse\\config\\config.yaml",
"DataRetentionDays": 60,
"ProbeSettings": {
"MaxConcurrentProbes": 100,
"MaxConcurrentProbes": 20,
"TimeoutMs": 5000,
"RetryCount": 2,
"FlapDamping": {
Expand All @@ -78,6 +78,6 @@
}
},
"Monitoring": {
"MaxConcurrentProbes": 100
"MaxConcurrentProbes": 20
}
}
2 changes: 1 addition & 1 deletion ThingConnect.Pulse/probes-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public sealed class Outage
```json
{
"Monitoring": {
"MaxConcurrentProbes": 100
"MaxConcurrentProbes": 20
}
}
```
Expand Down
Loading