Skip to content

Commit 41dcb9c

Browse files
committed
update docs on aspnet core healt check publishing and reporting docs
1 parent f904c0e commit 41dcb9c

File tree

3 files changed

+67
-26
lines changed

3 files changed

+67
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "Metrics"
3+
draft: false
4+
weight: 6
5+
icon: "/images/health.png"
6+
---
7+
8+
The [App.Metrics.Extensions.HealthChecks](https://www.nuget.org/packages/App.Metrics.Extensions.HealthChecks/) nuget package records AspNetCore health check results as metrics allowing results to be flushed to a supported TSDB via one of the App Metrics metrics [available reporters]({{< ref "reporting/reporters/_index.md" >}}).
9+
10+
11+
## How to use
12+
13+
With App Metrics configured in either an AspNetCore application or dotnet core application enable the `Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheckPublisher` implementation to record health check results as metrics on the `IServiceCollection`
14+
15+
```csharp
16+
services.AddAppMetricsHealthPublishing();
17+
```

content/reporting/health-reporters/metrics.md

-13
This file was deleted.

content/web-monitoring/aspnet-core/reporting.md

+50-13
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ weight: 5
66
icon: "/images/reporting.png"
77
---
88

9-
The [App.Metrics.AspNetCore.Reporting](https://www.nuget.org/packages/App.Metrics.AspNetCore.Reporting/) nuget package provides functionality to schedule metrics reporting using one or more of the [metric reporters]({{< ref "reporting/reporters/_index.md" >}}) in an ASP.NET Core application.
9+
The [App.Metrics.Extensions.Hosting](https://www.nuget.org/packages/App.Metrics.Extensions.Hosting/) nuget package provides functionality to schedule metrics reporting using one or more of the [metric reporters]({{< ref "reporting/reporters/_index.md" >}}) in an ASP.NET Core application.
1010

11-
App Metrics uses an [Microsoft.Extensions.Hosting.IHostedService](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.ihostedservice?view=aspnetcore-2.0) implementation for scheduling reporters which is automatically configured if reporting is enabled when using the `UseMetrics` [Microsoft.Extensions.Hosting.IWebHostBuilder](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.iwebhostbuilder?view=aspnetcore-2.0) extensions.
11+
App Metrics uses a [Microsoft.Extensions.Hosting.IHostedService](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.ihostedservice?view=aspnetcore-2.0) implementation for scheduling reporters which is automatically configured if reporting is enabled when using the `UseMetrics` [Microsoft.Extensions.Hosting.IHostBuilder](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.ihostbuilder?view=dotnet-plat-ext-3.1) extensions.
1212

1313
## How to use
1414

15-
`App.Metrics.AspNetCore.Reporting` can be configured a couple of ways in an ASP.NET Core application:
15+
Reporting can be configured a few of ways in an ASP.NET Core application:
1616

17-
1. Using the `Microsoft.AspNetCore.WebHost` in a `Program.cs`.
17+
1. Using the legacy `Microsoft.AspNetCore.WebHost` in a `Program.cs`.
18+
1. Using the `Microsoft.Extensions.Hosting.Host` in a `Program.cs`.
1819
1. Using the `Microsoft.AspNetCore.Builder.IApplicationBuilder` in a `Startup.cs`.
1920

2021
<i class="fa fa-hand-o-right"></i> First create a [new ASP.NET Core MVC project](https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc).
@@ -23,10 +24,10 @@ App Metrics uses an [Microsoft.Extensions.Hosting.IHostedService](https://docs.m
2324

2425
This is a simpler approach as it will wire up the App Metrics feature middleware on the IApplicationBuilder, as well as the metrics infrastructure on the `IServiceCollection` for you.
2526

26-
<i class="fa fa-hand-o-right"></i> First install the [nuget package](https://www.nuget.org/packages/App.Metrics.AspNetCore/):
27+
<i class="fa fa-hand-o-right"></i> First install the [nuget package](https://www.nuget.org/packages/App.Metrics.AspNetCore.All/):
2728

2829
```console
29-
nuget install App.Metrics.AspNetCore
30+
nuget install App.Metrics.AspNetCore.All
3031
```
3132

3233
<i class="fa fa-hand-o-right"></i> Then modify the `Program.cs` using the `UseMetrics` extension on `IWebHostBuilder` to configure all the App Metrics defaults including report scheduling, and also the `ConfigureMetricsWithDefaults` extension method to add the desired [metrics reporter(s)]({{< ref "reporting/reporters/_index.md" >}}).
@@ -52,20 +53,56 @@ public static class Program
5253
}
5354
```
5455

55-
### Bootstrapping Startup.cs
56+
### Bootstrapping Microsoft.Extensions.Hosting.Host
5657

57-
The [App.Metrics.AspNetCore](https://www.nuget.org/packages/App.Metrics.AspNetCore/) nuget packages is sort of a meta package which references other App Metrics ASP.NET core features. If it is preferred to cherry pick App Metrics ASP.NET Core functionality, feature packages can be referenced explicity instead, in this case we can configure App Metrics report scheduling using `IApplicationBuider` extensions in the `Startup.cs`.
58+
This is a simpler approach as it will wire up the App Metrics feature middleware on the IApplicationBuilder, as well as the metrics infrastructure on the `IServiceCollection` for you.
5859

59-
<i class="fa fa-hand-o-right"></i> First install the [nuget package](https://www.nuget.org/packages/App.Metrics.AspNetCore.Reporting/):
60+
<i class="fa fa-hand-o-right"></i> First install the [nuget package](https://www.nuget.org/packages/App.Metrics.AspNetCore.All/):
6061

6162
```console
62-
nuget install App.Metrics.AspNetCore.Reporting
63+
nuget install App.Metrics.AspNetCore.All
6364
```
6465

65-
{{% notice note %}}
66-
The `App.Metrics.AspNetCore.Reporting` nuget package only references core ASP.NET Core App Metrics functionality rather than all available feature packages.
66+
<i class="fa fa-hand-o-right"></i> Then modify the `Program.cs` using the `UseMetrics` extension on `IHostBuilder` to configure all the App Metrics defaults including report scheduling, and also the `ConfigureMetricsWithDefaults` extension method to add the desired [metrics reporter(s)]({{< ref "reporting/reporters/_index.md" >}}).
67+
68+
```csharp
69+
public static class Program
70+
{
71+
public static IHost BuildHost(string[] args)
72+
{
73+
return Host.CreateDefaultBuilder(args)
74+
.ConfigureMetricsWithDefaults(
75+
builder =>
76+
{
77+
builder.Report.ToConsole(TimeSpan.FromSeconds(2));
78+
builder.Report.ToTextFile(@"C:\metrics.txt", TimeSpan.FromSeconds(20));
79+
})
80+
.UseMetrics()
81+
.ConfigureWebHostDefaults(webBuilder =>
82+
{
83+
webBuilder.UseStartup<Startup>();
84+
});
85+
.Build();
86+
}
87+
88+
public static void Main(string[] args) { BuildHost(args).Run(); }
89+
}
90+
```
91+
92+
{{% notice tip %}}
93+
The same approach can be used for non-web applications using the Hosting building via the [App.Metrics.App.All](https://www.nuget.org/packages/App.Metrics.App.All/) nuget package.
6794
{{% /notice %}}
6895

96+
### Bootstrapping Startup.cs
97+
98+
The [App.Metrics.AspNetCore.All](https://www.nuget.org/packages/App.Metrics.AspNetCore.All/) nuget packages is a metapackage which references all App Metrics ASP.NET core features. If it is preferred to cherry pick App Metrics ASP.NET Core functionality, feature packages can be referenced explicity instead, in this case we can configure App Metrics report scheduling using `IApplicationBuider` extensions in the `Startup.cs`.
99+
100+
<i class="fa fa-hand-o-right"></i> First install the [nuget package](https://www.nuget.org/packages/App.Metrics.AspNetCore.All/):
101+
102+
```console
103+
nuget install App.Metrics.AspNetCore.All
104+
```
105+
69106
<i class="fa fa-hand-o-right"></i> Then modify the `Startup.cs` to add App Metrics and the metrics report scheduling feature using the `IServiceCollection` extensions:
70107

71108
```csharp
@@ -91,7 +128,7 @@ public class Startup
91128
```
92129

93130
{{% notice info %}}
94-
The `App.Metrics.AspNetCore.Reporting` nuget package does not reference any metric reporter packages, install and configure one of the [available reporters]({{< ref "reporting/reporters/_index.md" >}}) in the *"configure a reporter"* comment in the previous code snippet.
131+
The `App.Metrics.AspNetCore.All` nuget package does not reference any metric reporter packages, install and configure one of the [available reporters]({{< ref "reporting/reporters/_index.md" >}}) in the *"configure a reporter"* comment in the previous code snippet.
95132
{{% /notice %}}
96133

97134
{{% notice tip %}}

0 commit comments

Comments
 (0)