Configuration of. Net application monitoring library Metrics.NET

The configuration of the Metrics.NET library can be done using the Config property of the static Metric class.

Global context name

The root context of an indicator in a process can be configured (in descending order of priority):

  1. Set global variable: Metrics.GlobalContextName
  2. Set App Settings keyword "Metrics.GlobalContextName"
  3. If the following is not 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 by the process name
  • $Env.AppDomainAppVirtualPath $will be replaced with the virtual path of the app
  • $Env. $is replaced with the corresponding value in the environment variable

Sample configuration





    .WithReporting(config => config





App.Config configuration

The following configuration items can be put into app.config (or web.config) to control the Metrics.NET class 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"/>

Posted by Gayner on Thu, 30 Apr 2020 04:45:47 -0700