From 32c9e99336318d4c843bfe170dc44fa8326bdada Mon Sep 17 00:00:00 2001 From: alhardy Date: Sat, 7 Jul 2018 02:17:05 +1000 Subject: [PATCH] health reporting package updates, sample updated --- build/dependencies.props | 9 +++--- ...GrafanaCloudHostedMetricsSandboxMvc.csproj | 2 +- .../Host.cs | 30 +++++++++++-------- .../appsettings.json | 8 +++-- src/Directory.Build.props | 2 +- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 6e28a89..c4fed7e 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,14 +1,15 @@ 3.0.0-* + 2.1.0-* 3.0.0-* 2.1.0-* 3.0.0-* - 2.1.0 - 2.1.0 - 2.1.0 + 2.1.1 + 2.1.1 + 2.1.1 4.5.0 - 2.1.0 + 2.1.1 4.8.2 11.0.2 15.8.0-preview-20180510-03 diff --git a/sandbox/GrafanaCloudHostedMetricsSandboxMvc/GrafanaCloudHostedMetricsSandboxMvc.csproj b/sandbox/GrafanaCloudHostedMetricsSandboxMvc/GrafanaCloudHostedMetricsSandboxMvc.csproj index 374b78c..900375f 100644 --- a/sandbox/GrafanaCloudHostedMetricsSandboxMvc/GrafanaCloudHostedMetricsSandboxMvc.csproj +++ b/sandbox/GrafanaCloudHostedMetricsSandboxMvc/GrafanaCloudHostedMetricsSandboxMvc.csproj @@ -12,7 +12,7 @@ - + diff --git a/sandbox/GrafanaCloudHostedMetricsSandboxMvc/Host.cs b/sandbox/GrafanaCloudHostedMetricsSandboxMvc/Host.cs index c391efd..6e9309d 100644 --- a/sandbox/GrafanaCloudHostedMetricsSandboxMvc/Host.cs +++ b/sandbox/GrafanaCloudHostedMetricsSandboxMvc/Host.cs @@ -7,6 +7,8 @@ using System.Threading.Tasks; using App.Metrics; using App.Metrics.AspNetCore; +using App.Metrics.AspNetCore.Health; +using App.Metrics.Extensions.Configuration; using App.Metrics.Health; using App.Metrics.Reporting.GrafanaCloudHostedMetrics; using Microsoft.AspNetCore; @@ -35,26 +37,28 @@ public static IWebHost BuildWebHost(string[] args) // Samples with weight of less than 10% of average should be discarded when rescaling const double minimumSampleWeight = 0.001; + var metrics = AppMetrics.CreateDefaultBuilder() + .Configuration.ReadFrom(configuration) + .SampleWith.ForwardDecaying( + AppMetricsReservoirSamplingConstants.DefaultSampleSize, + AppMetricsReservoirSamplingConstants.DefaultExponentialDecayFactor, + minimumSampleWeight: minimumSampleWeight) + .Report.ToHostedMetrics(grafanaCloudHostedMetricsOptions) + .Build(); + return WebHost.CreateDefaultBuilder(args) - .ConfigureMetricsWithDefaults( - builder => - { - builder.SampleWith.ForwardDecaying( - AppMetricsReservoirSamplingConstants.DefaultSampleSize, - AppMetricsReservoirSamplingConstants.DefaultExponentialDecayFactor, - minimumSampleWeight: minimumSampleWeight); - builder.Report.ToHostedMetrics(grafanaCloudHostedMetricsOptions); - }) + .ConfigureMetrics(metrics) .ConfigureHealthWithDefaults( - (context, services, builder) => + (context, builder) => { builder.OutputHealth.AsPlainText() .OutputHealth.AsJson() .HealthChecks.AddCheck("check 1", () => new ValueTask(HealthCheckResult.Healthy())) - .HealthChecks.AddCheck("check 2", () => new ValueTask(HealthCheckResult.Healthy())) - .HealthChecks.AddCheck("check 3", () => new ValueTask(HealthCheckResult.Healthy())) - .RecordResultsAsMetrics(services, TimeSpan.FromSeconds(10)); + .HealthChecks.AddCheck("check 2", () => new ValueTask(HealthCheckResult.Degraded())) + .HealthChecks.AddCheck("check 3", () => new ValueTask(HealthCheckResult.Unhealthy())) + .Report.ToMetrics(metrics); }) + .UseHealth() .UseMetrics() .UseSerilog() .UseStartup() diff --git a/sandbox/GrafanaCloudHostedMetricsSandboxMvc/appsettings.json b/sandbox/GrafanaCloudHostedMetricsSandboxMvc/appsettings.json index d2a47e3..4a57db1 100644 --- a/sandbox/GrafanaCloudHostedMetricsSandboxMvc/appsettings.json +++ b/sandbox/GrafanaCloudHostedMetricsSandboxMvc/appsettings.json @@ -1,7 +1,11 @@ { "MetricsOptions": { "DefaultContextLabel": "GrafanaCloudSandboxMvc", - "Enabled": true + "Enabled": true + }, + "HealthOptions": { + "Enabled": true, + "ReportingEnabled": true }, "MetricsWebTrackingOptions": { "ApdexTrackingEnabled": true, @@ -20,7 +24,7 @@ "HttpPolicy": { "BackoffPeriod": "0:0:30", "FailuresBeforeBackoff": 5, - "Timeout": "0:0:40" + "Timeout": "0:0:40" }, "ReportInterval": "0:0:1" }, diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 80ec7c1..7548caf 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,5 +1,5 @@ - + \ No newline at end of file