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):
- Set global variable: Metrics.GlobalContextName
- Set App Settings keyword "Metrics.GlobalContextName"
- 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
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 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"/>