Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
health reporting package updates, sample updated
Browse files Browse the repository at this point in the history
  • Loading branch information
alhardy committed Jul 6, 2018
1 parent a4c45e1 commit 32c9e99
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
9 changes: 5 additions & 4 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project>
<PropertyGroup>
<AppMetricsCoreVersion>3.0.0-*</AppMetricsCoreVersion>
<AppMetricsHealthCoreVersion>2.1.0-*</AppMetricsHealthCoreVersion>
<AppMetricsAspNetCoreVersion>3.0.0-*</AppMetricsAspNetCoreVersion>
<AppMetricsAspNetCoreHealthVersion>2.1.0-*</AppMetricsAspNetCoreHealthVersion>
<AppMetricsMicrosoftExtensionsVersion>3.0.0-*</AppMetricsMicrosoftExtensionsVersion>
<AspNetCoreVersion>2.1.0</AspNetCoreVersion>
<AspNetCoreMvcVersion>2.1.0</AspNetCoreMvcVersion>
<MicrosoftExtensionsVersion>2.1.0</MicrosoftExtensionsVersion>
<AspNetCoreVersion>2.1.1</AspNetCoreVersion>
<AspNetCoreMvcVersion>2.1.1</AspNetCoreMvcVersion>
<MicrosoftExtensionsVersion>2.1.1</MicrosoftExtensionsVersion>
<CoreFxVersion>4.5.0</CoreFxVersion>
<DependencyModelVersion>2.1.0</DependencyModelVersion>
<DependencyModelVersion>2.1.1</DependencyModelVersion>
<MoqVersion>4.8.2</MoqVersion>
<NewtonsoftVersion>11.0.2</NewtonsoftVersion>
<TestSdkVersion>15.8.0-preview-20180510-03</TestSdkVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="App.Metrics.AspNetCore.Health" Version="$(AppMetricsAspNetCoreHealthVersion)" />
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="$(AppMetricsAspNetCoreVersion)" />
<PackageReference Include="App.Metrics.HealthMetrics.Extensions.Hosting" Version="$(AppMetricsMicrosoftExtensionsVersion)" />
<PackageReference Include="App.Metrics.Health.Reporting.Metrics" Version="$(AppMetricsHealthCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreMvcVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(MicrosoftExtensionsVersion)" />
Expand Down
30 changes: 17 additions & 13 deletions sandbox/GrafanaCloudHostedMetricsSandboxMvc/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>(HealthCheckResult.Healthy()))
.HealthChecks.AddCheck("check 2", () => new ValueTask<HealthCheckResult>(HealthCheckResult.Healthy()))
.HealthChecks.AddCheck("check 3", () => new ValueTask<HealthCheckResult>(HealthCheckResult.Healthy()))
.RecordResultsAsMetrics(services, TimeSpan.FromSeconds(10));
.HealthChecks.AddCheck("check 2", () => new ValueTask<HealthCheckResult>(HealthCheckResult.Degraded()))
.HealthChecks.AddCheck("check 3", () => new ValueTask<HealthCheckResult>(HealthCheckResult.Unhealthy()))
.Report.ToMetrics(metrics);
})
.UseHealth()
.UseMetrics()
.UseSerilog()
.UseStartup<Startup>()
Expand Down
8 changes: 6 additions & 2 deletions sandbox/GrafanaCloudHostedMetricsSandboxMvc/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"MetricsOptions": {
"DefaultContextLabel": "GrafanaCloudSandboxMvc",
"Enabled": true
"Enabled": true
},
"HealthOptions": {
"Enabled": true,
"ReportingEnabled": true
},
"MetricsWebTrackingOptions": {
"ApdexTrackingEnabled": true,
Expand All @@ -20,7 +24,7 @@
"HttpPolicy": {
"BackoffPeriod": "0:0:30",
"FailuresBeforeBackoff": 5,
"Timeout": "0:0:40"
"Timeout": "0:0:40"
},
"ReportInterval": "0:0:1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<ItemGroup>
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.1" PrivateAssets="All" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="All" />
</ItemGroup>
</Project>

0 comments on commit 32c9e99

Please sign in to comment.