Http

The App.Metrics.Reporting.Http nuget package reports metrics to a custom HTTP endpoint. The default output is JSON using App.Metrics.Formatters.JSON which can be substituted with any other App Metrics Formatter.

Getting started

To use the HTTP reporter, first install the nuget package:

nuget install App.Metrics.Reporting.HTTP

Then enable the reporter using Report.OverHttp(url):

var metrics = new MetricsBuilder()
    .Report.OverHttp("http://localhost/metrics")
    .Build();

App Metrics at the moment leaves report scheduling up the the user unless using App.Metrics.AspNetCore. To run all configured reports use the ReportRunner on IMetricsRoot:

await metrics.ReportRunner.RunAllAsync();

Report Scheduling will be added when Microsoft.Extensions.Hosting.Background is released, otherwise there are various other scheduling solutions available for C#.

Configuration

Configuration options are provided as a setup action used with OverHttp().

To configure HTTP reporting options:

var filter = new MetricsFilter().WhereType(MetricType.Timer);
var metrics = new MetricsBuilder()
    .Report.OverHttp(
        options => {
            options.HttpSettings.RequestUri = new Uri("http://localhost/metrics");.
            options.HttpSettings.UserName = "admin";
            options.HttpSettings.Password = "password";
            options.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
            options.HttpPolicy.FailuresBeforeBackoff = 5;
            options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
            options.MetricsOutputFormatter = new MetricsJsonOutputFormatter();
            options.Filter = filter;
            options.FlushInterval = TimeSpan.FromSeconds(20);
        })
    .Build();

The configuration options are:

Option Description
MetricsOutputFormatter The formatter used when reporting metrics over HTTP.
Filter The filter used to filter metrics just for this reporter.
FlushInterval The delay between reporting metrics over HTTP.
HttpSettings.RequestUri The endpoint accepting metrics in the specified format.
HttpSettings.UserName The username when using basic auth on the metrics ingress endpoint.
HttpSettings.Password The password when using basic auth on the metrics ingress endpoint.
HttpPolicy.BackoffPeriod The TimeSpan to back-off when metrics are failing to report to the metrics ingress endpoint.
HttpPolicy.FailuresBeforeBackoff The number of failures before backing-off when metrics are failing to report to the metrics ingress endpoint.
HttpPolicy.Timeout The HTTP timeout duration when attempting to report metrics to the metrics ingress endpoint.