private async Task ReportHealth(IMetricReporter reporter, IMetrics metrics, CancellationToken token) { var healthStatus = await metrics.Health.ReadStatusAsync(token); var passed = healthStatus.Results.Where(r => r.Check.Status.IsHealthy()).ToArray(); var failed = healthStatus.Results.Where(r => r.Check.Status.IsUnhealthy()).ToArray(); var degraded = healthStatus.Results.Where(r => r.Check.Status.IsDegraded()).ToArray(); reporter.ReportHealth(_options.GlobalTags, passed, degraded, failed); foreach (var check in passed) { metrics.Measure.Counter.Increment(ApplicationHealthMetricRegistry.HealthyCheckCounter, check.Name); } foreach (var check in degraded) { metrics.Measure.Counter.Increment(ApplicationHealthMetricRegistry.DegradedCheckCounter, check.Name); } foreach (var check in failed) { metrics.Measure.Counter.Increment(ApplicationHealthMetricRegistry.UnhealthyCheckCounter, check.Name); } }
internal async Task Generate(IMetricReporter reporter, IMetrics metrics, IMetricsFilter reporterMetricsFilter, CancellationToken token) { if (reporterMetricsFilter == default(IMetricsFilter)) { reporterMetricsFilter = metrics.Advanced.GlobalFilter; } reporter.StartReport(metrics); var data = await metrics.Advanced.Data.ReadDataAsync(reporterMetricsFilter); if (data.Environment.Entries.Any() && reporterMetricsFilter.ReportEnvironment) { reporter.StartMetricTypeReport(typeof(EnvironmentInfo)); reporter.ReportEnvironment(data.Environment); reporter.EndMetricTypeReport(typeof(EnvironmentInfo)); } foreach (var contextValueSource in data.Contexts) { ReportMetricType(reporter, contextValueSource.Counters, c => { reporter.ReportMetric($"{contextValueSource.Context}", c); }, token); ReportMetricType(reporter, contextValueSource.Gauges, g => { reporter.ReportMetric($"{contextValueSource.Context}", g); }, token); ReportMetricType(reporter, contextValueSource.Histograms, h => { reporter.ReportMetric($"{contextValueSource.Context}", h); }, token); ReportMetricType(reporter, contextValueSource.Meters, m => { reporter.ReportMetric($"{contextValueSource.Context}", m); }, token); ReportMetricType(reporter, contextValueSource.Timers, t => { reporter.ReportMetric($"{contextValueSource.Context}", t); }, token); } if (reporterMetricsFilter.ReportHealthChecks) { var healthStatus = await metrics.Advanced.Health.ReadStatusAsync(); reporter.StartMetricTypeReport(typeof(HealthStatus)); var passed = healthStatus.Results.Where(r => r.Check.Status.IsHealthy()); var failed = healthStatus.Results.Where(r => r.Check.Status.IsUnhealthy()); var degraded = healthStatus.Results.Where(r => r.Check.Status.IsDegraded()); reporter.ReportHealth(passed, degraded, failed); reporter.EndMetricTypeReport(typeof(HealthStatus)); } reporter.EndReport(metrics); }
private async Task ReportHealth(IMetricReporter reporter, IMetrics metrics, CancellationToken token) { var healthStatus = await metrics.Health.ReadStatusAsync(token); var passed = healthStatus.Results.Where(r => r.Check.Status.IsHealthy()).ToArray(); var failed = healthStatus.Results.Where(r => r.Check.Status.IsUnhealthy()).ToArray(); var degraded = healthStatus.Results.Where(r => r.Check.Status.IsDegraded()).ToArray(); reporter.ReportHealth(_options.GlobalTags, passed, degraded, failed); }
public async Task <bool> GenerateAsync(IMetricReporter reporter, IMetrics metrics, IMetricsFilter reporterMetricsFilter, CancellationToken token) { var startTimestamp = _logger.IsEnabled(LogLevel.Information) ? Stopwatch.GetTimestamp() : 0; _logger.ReportedStarted(reporter); if (reporterMetricsFilter == default(IMetricsFilter)) { reporterMetricsFilter = metrics.Advanced.GlobalFilter; } reporter.StartReportRun(metrics); var data = metrics.Advanced.Data.ReadData(reporterMetricsFilter); if (data.Environment.Entries.Any() && reporterMetricsFilter.ReportEnvironment) { reporter.ReportEnvironment(data.Environment); } if (reporterMetricsFilter.ReportHealthChecks) { var healthStatus = await metrics.Advanced.Health.ReadStatusAsync(token); var passed = healthStatus.Results.Where(r => r.Check.Status.IsHealthy()).ToArray(); var failed = healthStatus.Results.Where(r => r.Check.Status.IsUnhealthy()).ToArray(); var degraded = healthStatus.Results.Where(r => r.Check.Status.IsDegraded()).ToArray(); reporter.ReportHealth(metrics.Advanced.GlobalTags, passed, degraded, failed); foreach (var check in passed) { metrics.Increment(ApplicationHealthMetricRegistry.HealthyCheckCounter, check.Name); } foreach (var check in degraded) { metrics.Increment(ApplicationHealthMetricRegistry.DegradedCheckCounter, check.Name); } foreach (var check in failed) { metrics.Increment(ApplicationHealthMetricRegistry.UnhealthyCheckCounter, check.Name); } } foreach (var contextValueSource in data.Contexts) { ReportMetricType(contextValueSource.Counters, c => { reporter.ReportMetric($"{contextValueSource.Context}", c); }, token); ReportMetricType(contextValueSource.Gauges, g => { reporter.ReportMetric($"{contextValueSource.Context}", g); }, token); ReportMetricType(contextValueSource.Histograms, h => { reporter.ReportMetric($"{contextValueSource.Context}", h); }, token); ReportMetricType(contextValueSource.Meters, m => { reporter.ReportMetric($"{contextValueSource.Context}", m); }, token); ReportMetricType(contextValueSource.Timers, t => { reporter.ReportMetric($"{contextValueSource.Context}", t); }, token); ReportMetricType(contextValueSource.ApdexScores, t => { reporter.ReportMetric($"{contextValueSource.Context}", t); }, token); } var result = await reporter.EndAndFlushReportRunAsync(metrics); _logger.ReportRan(reporter, startTimestamp); return(result); }