Skip to content

Http Endpoint Reports

Paul Parau edited this page Dec 2, 2016 · 2 revisions

###Http Endpoint Reports

Metrics.NET comes with the ability to serve metrics through HTTP endpoints.

To start a HttpListener:

Metric.Config.WithHttpEndpoint("http://localhost:1234/");

Run app and open http://localhost:1234/ in a browser.

If you are using NancyFx see Nancy Adapter .

If you are hosting your app inside IIS or any OWIN compatible server, OWIN Adapter is a much better option.

Default Endpoints

By default, Metrics.NET will serve the visualization app and json & text reports along with a health status report.

JSON metrics are available at /v2/json (latest version with context support) or /v1/json (initial version, without any context support). /json will provide /v1/json or /v2/json depending on the accepted mime types defined in the accept header of the request. Human readable text metrics are available at /text. The health status is accessible at /health or /v1/health.

The visualization app is now available at Metrics.NET.FlotVisualization.

Custom Endpoints

Endpoints that serve metrics in custom formats can also be configured by chaining calls to MetricsEndpointReports.WithEndpointReport

Metric.Config.WithHttpEndpoint("http://localhost:1234/", config => config
    .WithEndpointReport("sample", (d, h, r) => new MetricsEndpointResponse("sample", "text/plain")));

A simple way to build a new reporter is to provide an extension method for MetricsEndpointReports, which internally calls MetricsEndpointReports.WithEndpointReport. Then you can simply configure as follows, without needing to build the response factory inside the configuration block:

Metric.Config.WithHttpEndpoint("http://localhost:1234/", config => config
    .WithMyCustomEndpointReport("sample"/* any other parameters */));