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

Console Reporter

The App.Metrics.Extensions.Reporting.Console nuget package is an App Metrics report provider which will output metrics to a console at a specified interval.

  1. First see the getting started guide.
  2. Configure the console reporter as follows:
public class Host
{ 
    public static void Main()
    {
        IServiceCollection serviceCollection = new ServiceCollection();
        ConfigureServices(serviceCollection);
        ConfigureMetrics(serviceCollection);
        
        var provider = serviceCollection.BuildServiceProvider();
        provider.GetRequiredService<IMetrics>();
        
        var metrics = provider.GetRequiredService<IMetrics>();

        // TODO: use metrics to start measuring metrics
                    
        var reporterFactory = provider.GetRequiredService<IReportFactory>();
        var reporter = reporterFactory.CreateReporter();
        // Will continue to run for the configured report internal
        reporter.RunReports(metrics);           

        Console.ReadKey();
    }

    private static void ConfigureMetrics(IServiceCollection services)
    {
        services
            .AddMetrics()
            .AddHealthChecks()
            .AddReporting(factory =>
            {                    
                factory.AddConsole(
                    new ConsoleReporterSettings
                    {
                        ReportInterval = TimeSpan.FromSeconds(20),
                    },                    
                    new AsciiMetricPayloadBuilder());
            });
    }

    private static void ConfigureServices(IServiceCollection services)
    {                      
        var loggerFactory = new LoggerFactory();
        loggerFactory.AddConsole((l, s) => s == LogLevel.Trace);            
        services.AddSingleton<ILoggerFactory, LoggerFactory>();
        services.AddLogging();            
    }       
} 
Tip

The example above is using the AsciiMetricPayloadBuilder, this can be substituted with with any of the InfluxDB, Elasticsearch, Prometheus, Graphite, App Metrics JSON, or a custom payload builder.

  • Edit this Doc
Back to top Copyright © 2017 Allan Hardy
Generated by DocFX