Skip to content
Merged
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
1 change: 1 addition & 0 deletions Lite/Controls/ServerTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public partial class ServerTab : UserControl
private readonly ServerConnection _server;
private readonly LocalDataService _dataService;
private readonly int _serverId;
public int ServerId => _serverId;
private readonly CredentialService _credentialService;
private readonly DispatcherTimer _refreshTimer;
private readonly Dictionary<ScottPlot.WPF.WpfPlot, ScottPlot.Panels.LegendPanel?> _legendPanels = new();
Expand Down
10 changes: 9 additions & 1 deletion Lite/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ private void ServerTabControl_SelectionChanged(object sender, SelectionChangedEv
{
ServerTimeHelper.UtcOffsetMinutes = serverTab.UtcOffsetMinutes;
}

UpdateCollectorHealth();
}

private void RefreshServerList()
Expand Down Expand Up @@ -290,7 +292,13 @@ private void UpdateCollectorHealth()
return;
}

var health = _collectorService.GetHealthSummary();
int? selectedServerId = null;
if (ServerTabControl.SelectedItem is TabItem { Content: ServerTab serverTab })
{
selectedServerId = serverTab.ServerId;
}

var health = _collectorService.GetHealthSummary(selectedServerId);

if (health.TotalCollectors == 0)
{
Expand Down
26 changes: 16 additions & 10 deletions Lite/Services/RemoteCollectorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace PerformanceMonitorLite.Services;
/// </summary>
public class CollectorHealthEntry
{
public int ServerId { get; set; }
public string CollectorName { get; set; } = "";
public DateTime? LastSuccessTime { get; set; }
public DateTime? LastErrorTime { get; set; }
Expand Down Expand Up @@ -82,9 +83,9 @@ public partial class RemoteCollectorService
private long _lastDuckDbMs;

/// <summary>
/// Tracks health state per collector (keyed by collector name).
/// Tracks health state per collector per server.
/// </summary>
private readonly Dictionary<string, CollectorHealthEntry> _collectorHealth = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<(int ServerId, string CollectorName), CollectorHealthEntry> _collectorHealth = new();
private readonly object _healthLock = new();

/// <summary>
Expand Down Expand Up @@ -113,20 +114,24 @@ public RemoteCollectorService(
public Task SeedDeltaCacheAsync() => _deltaCalculator.SeedFromDatabaseAsync(_duckDb);

/// <summary>
/// Gets a summary of collector health across all tracked collectors.
/// Gets a summary of collector health. When serverId is provided, filters to that server only.
/// </summary>
public CollectorHealthSummary GetHealthSummary()
public CollectorHealthSummary GetHealthSummary(int? serverId = null)
{
lock (_healthLock)
{
var summary = new CollectorHealthSummary
{
TotalCollectors = _collectorHealth.Count,
LoggingFailures = _logInsertFailures
};

foreach (var entry in _collectorHealth.Values)
{
if (serverId.HasValue && entry.ServerId != serverId.Value)
continue;

summary.TotalCollectors++;

if (entry.ConsecutiveErrors > 0)
{
summary.ErroringCollectors++;
Expand All @@ -141,14 +146,15 @@ public CollectorHealthSummary GetHealthSummary()
/// <summary>
/// Records a collector execution result for health tracking.
/// </summary>
private void RecordCollectorResult(string collectorName, bool success, string? errorMessage = null)
private void RecordCollectorResult(int serverId, string collectorName, bool success, string? errorMessage = null)
{
lock (_healthLock)
{
if (!_collectorHealth.TryGetValue(collectorName, out var entry))
var key = (serverId, collectorName);
if (!_collectorHealth.TryGetValue(key, out var entry))
{
entry = new CollectorHealthEntry { CollectorName = collectorName };
_collectorHealth[collectorName] = entry;
entry = new CollectorHealthEntry { ServerId = serverId, CollectorName = collectorName };
_collectorHealth[key] = entry;
}

if (success)
Expand Down Expand Up @@ -330,7 +336,7 @@ public async Task RunCollectorAsync(ServerConnection server, string collectorNam
}

// Track collector health
RecordCollectorResult(collectorName, status == "SUCCESS", errorMessage);
RecordCollectorResult(GetServerId(server), collectorName, status == "SUCCESS", errorMessage);

// Log the collection attempt
await LogCollectionAsync(GetServerId(server), collectorName, startTime, status, errorMessage, rowsCollected, _lastSqlMs, _lastDuckDbMs);
Expand Down