Skip to content
Paul Parau edited this page Dec 23, 2016 · 9 revisions

Configuration of the metrics library can be done using the Config property of the static Metric class.

Global context name

The root context name for metrics inside a process can be configured in the following ways (in decreasing order of priority):

  1. Set the environment variable: Metrics.GlobalContextName
  2. Set the app settings key Metrics.GlobalContextName
  3. If none of the above is set the default is MachineName.ProcessName

The global context name can contain the following variable placeholders:

  • $Env.MachineName$ will be replaced with the machine name
  • $Env.ProcessName$ will be replaced with the process name
  • $Env.AppDomainAppVirtualPath$ will be replaced with the app virtual path
  • $Env.$ will be replaced with the corresponding environment variable
Sample config
Metric.Config
    .WithHttpEndpoint("http://localhost:1234/metrics/")
    .WithAllCounters()
    .WithInternalMetrics()
    .WithReporting(config => config
        .WithConsoleReport(TimeSpan.FromSeconds(30))
        .WithCSVReports(@"c:\temp\reports\", TimeSpan.FromMinutes(30))
        .WithTextFileReport(@"C:\temp\reports\metrics.txt", TimeSpan.FromHours(1))
    );
App.Config settings

The following settings can be placed in the app.config ( or web.config ) file to control a few aspects of the Metrics.NET library:

<!-- Completely disable all metrics -->
<add key="Metrics.CompletelyDisableMetrics" value="true"/>

<!-- Equivalent of calling Metric.Config.WithHttpEndpoint("http://localhost:1234/") -->
<add key="Metrics.HttpListener.HttpUriPrefix" value="http://localhost:1234/"/>

<!-- Equivalent of calling 
Metric.Config.WithReporting(config => 
config.WithCSVReports(@"..\MetricsCSV\", TimeSpan.FromSeconds(10))
-->
<add key="Metrics.CSV.Path" value="..\MetricsCSV\"/>
<add key="Metrics.CSV.Interval.Seconds" value="10"/>

<!-- Specify how many times a scheduled reporter can consecutively fail to push data.
-1  : unlimited
0   : reporter stops trying to send data once an attempt to push fails (default)
x>0 : reporter tolerates x consecutive failures. If the number of failures is greater than x, the reporter stops.
Regardless of setting, each failure is handled by the MetricsErrorHandler.
-->
<add key="Metrics.Reports.ToleratedConsecutiveFailures" value="3"/>