Skip to content
etishor edited this page Oct 18, 2014 · 1 revision

To start using the library, install the Metrics.NET NuGet package, using the package management UI or from the package management console run:

Install-Package Metrics.NET

Add the following Metrics.NET configuration code somewhere in the initialization section of your application:

using Metrics;

Metric.Config
    .WithHttpEndpoint("http://localhost:1234/")
    .WithAllCounters();

Run the application and point a web browser to http://localhost:1234/

The Metrics Visualization App should already have a number of Gauges that are captured from various performance counters.

You can now start measuring things:

public class SampleMetrics
{
    private readonly Timer timer = Metric.Timer("Requests", Unit.Requests);
    private readonly Counter counter = Metric.Counter("ConcurrentRequests", Unit.Requests);

    public void Request(int i)
    {
        this.counter.Increment();
        using (this.timer.NewContext()) // measure until disposed
        {
            // do some work
        }
        this.counter.Decrement();
    }
}