App Metrics 1.0 Fork me on GitHub
Show / Hide Table of Contents

ASP.NET Core Middleware JSON Formatting

To serialize metrics, environment information and/or health as JSON when /metrics, /metrics-text, /env and/or /health are requested:

  1. Add the App.Metrics.Formatters.Json nuget package to your ASP.NET Core web application.
  2. Configure JSON serialization in your Startup.cs
public class Startup
{
	public void ConfigureServices(IServiceCollection services)
	{
		services.AddMvc(options => options.AddMetricsResourceFilter());
		
		services.AddMetrics()
			// .AddJsonSerialization() - Enables json format on the /metrics-text, /metrics, /health and /env endpoints.
			.AddJsonMetricsSerialization() // Enables json format on the /metrics-text endpoint.
			.AddJsonMetricsTextSerialization() // Enables json format on the /metrics endpoint.
			.AddJsonHealthSerialization() // Enables json format on the /health endpont.
			.AddJsonEnvironmentInfoSerialization() // Enables json format on the /env endpont.
			.AddHealthChecks()
			.AddMetricsMiddleware();
	}

	public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
	{            
        app.UseMetrics();
		app.UseMvc();
	}
}
  • Edit this Doc
Back to top Copyright © 2017 Allan Hardy
Generated by DocFX