private async Task <UIHealthReport> GetHealthReport(HealthCheckConfiguration configuration) { var(uri, name) = configuration; try { var response = await _httpClient.GetAsync(uri); return(await response.As <UIHealthReport>()); } catch (Exception exception) { _logger.LogError(exception, $"GetHealthReport threw an exception when trying to get report from {uri} configured with name {name}."); return(UIHealthReport.CreateFrom(exception)); } }
public IHttpActionResult Get() { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); var entries = new Dictionary <string, HealthReportEntry>(); entries.Add("DI Controllers", HealthCheckHelper.TestaControllersInjection("HealthCheck.API", IoC.Container)); stopwatch.Stop(); var response = UIHealthReport.CreateFrom( new HealthReport(entries, TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds))); if (response.Status == UIHealthStatus.Healthy) { return(Ok(response)); } else { return(Content((System.Net.HttpStatusCode) 418, response)); } }
private void SaveExecutionHistoryEntries(UIHealthReport healthReport, HealthCheckExecution execution, DateTime lastExecutionTime) { _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values."); foreach (var item in execution.Entries) { var reportEntry = healthReport.Entries[item.Name]; if (item.Status != reportEntry.Status) { execution.History.Add(new HealthCheckExecutionHistory() { On = lastExecutionTime, Status = reportEntry.Status, Name = item.Name, Description = reportEntry.Description }); } } execution.OnStateFrom = lastExecutionTime; execution.LastExecuted = lastExecutionTime; execution.Status = healthReport.Status; }
private async Task SaveExecutionHistory(HealthCheckConfiguration configuration, UIHealthReport healthReport) { _logger.LogDebug("HealthReportCollector - health report execution history saved."); var execution = await GetHealthCheckExecution(configuration); var lastExecutionTime = DateTime.UtcNow; if (execution != null) { execution.Entries.Clear(); execution.Entries = healthReport.ToExecutionEntries(); if (execution.Status == healthReport.Status) { _logger.LogDebug("HealthReport history already exists and is in the same state, updating the values."); execution.LastExecuted = lastExecutionTime; } else { _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values."); execution.History.Add(new HealthCheckExecutionHistory() { On = lastExecutionTime, Status = execution.Status }); execution.OnStateFrom = lastExecutionTime; execution.LastExecuted = lastExecutionTime; execution.Status = healthReport.Status; } } else { _logger.LogDebug("Creating a new HealthReport history."); execution = new HealthCheckExecution() { LastExecuted = lastExecutionTime, OnStateFrom = lastExecutionTime, Entries = healthReport.ToExecutionEntries(), Status = healthReport.Status, Name = configuration.Name, Uri = configuration.Uri, DiscoveryService = configuration.DiscoveryService }; await _db.Executions .AddAsync(execution); } await _db.SaveChangesAsync(); }
public ValueTask OnCollectExecuted(UIHealthReport report) { _resetEvent.Set(); return(new ValueTask()); }
public async Task NotifyDown(string name, UIHealthReport report) { await Notify(name, failure : GetFailedMessageFromContent(report), isHealthy : false, description : GetFailedDescriptionsFromContent(report)); }
private async Task SaveExecutionHistory(HealthCheckConfiguration configuration, UIHealthReport healthReport) { _logger.LogDebug("HealthReportCollector - health report execution history saved."); var execution = await GetHealthCheckExecution(configuration); var lastExecutionTime = DateTime.UtcNow; if (execution != null) { //update existing entries from new health report foreach (var item in healthReport.ToExecutionEntries()) { var existing = execution.Entries .Where(e => e.Name == item.Name) .SingleOrDefault(); if (existing != null) { existing.Status = item.Status; existing.Description = item.Description; existing.Duration = item.Duration; } else { execution.Entries.Add(item); } } //remove old entries in existing execution not present in new health report foreach (var item in execution.Entries) { var existing = healthReport.Entries .ContainsKey(item.Name); if (!existing) { var oldEntry = execution.Entries .Where(t => t.Name == item.Name) .SingleOrDefault(); _db.HealthCheckExecutionEntries .Remove(oldEntry); } } if (execution.Status == healthReport.Status) { _logger.LogDebug("HealthReport history already exists and is in the same state, updating the values."); execution.LastExecuted = lastExecutionTime; } else { _logger.LogDebug("HealthCheckReportCollector already exists but on different state, updating the values."); execution.History.Add(new HealthCheckExecutionHistory() { On = lastExecutionTime, Status = execution.Status }); execution.OnStateFrom = lastExecutionTime; execution.LastExecuted = lastExecutionTime; execution.Status = healthReport.Status; } } else { _logger.LogDebug("Creating a new HealthReport history."); execution = new HealthCheckExecution() { LastExecuted = lastExecutionTime, OnStateFrom = lastExecutionTime, Entries = healthReport.ToExecutionEntries(), Status = healthReport.Status, Name = configuration.Name, Uri = configuration.Uri, DiscoveryService = configuration.DiscoveryService }; await _db.Executions .AddAsync(execution); } await _db.SaveChangesAsync(); }
public async Task NotifyDown(string name, UIHealthReport report) { await NotifyAsync(name, report, isHealthy : false); }
public ValueTask OnCollectExecuted(UIHealthReport report) { _resetEvent.Set(); return(default);