Skip to content

Commit

Permalink
Health check publisher now include checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Feb 29, 2024
1 parent bbecda6 commit 90d7197
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Elmah.Io.AspNetCore.HealthChecks/ElmahIoPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public async Task PublishAsync(HealthReport report, CancellationToken cancellati

var createHeartbeat = new CreateHeartbeat
{
Result = Result(report),
Result = Result(report.Status),
Reason = Reason(report),
Application = options.Application,
Took = Took(report),
Checks = Checks(report),
};

if (options.OnFilter != null && options.OnFilter(createHeartbeat))
Expand All @@ -78,6 +79,20 @@ public async Task PublishAsync(HealthReport report, CancellationToken cancellati
}
}

private List<Check> Checks(HealthReport report)
{
return report
.Entries?
.Select(entry => new Check
{
Name = entry.Key,
Result = Result(entry.Value.Status),
Reason = entry.Value.Description,
Took = (long?)entry.Value.Duration.TotalMilliseconds,
})
.ToList();
}

private long? Took(HealthReport report)
{
return (long?)report?.TotalDuration.TotalMilliseconds;
Expand Down Expand Up @@ -127,9 +142,9 @@ private void Generate(StringBuilder sb, List<KeyValuePair<string, HealthReportEn
}
}

private string Result(HealthReport report)
private string Result(HealthStatus status)
{
switch (report.Status)
switch (status)
{
case HealthStatus.Degraded:
return "Degraded";
Expand Down

0 comments on commit 90d7197

Please sign in to comment.