# Performance Metrics

Tracking system metrics such as gc, memory and cpu usage is very useful to compare against feature usage and other metrics to identify possible bottlenecks.

Toggly makes use of .net's built-in Performance Counters, and enables you to monitor any metrics exposed through Performance Counters, whether out-of-the-box or custom.&#x20;

### Add Performance Metrics to your application

Install the `Toggly.Metrics.SystemMetrics` package

```powershell
Install-Package Toggly.Metrics.SystemMetrics
```

Register collection of the performance metrics you want to collect.

The service takes in a `Dictionary<`**`Event Source Name`**`, Dictionary<`**`Counter Name`**`,`` `**`Metric Name in Toggly`**`>>`

```csharp
services.AddPerformanceMetrics(new Dictionary<string, Dictionary<string, string>>
{
    {  "System.Runtime", new Dictionary<string, string>
        {
            {"time-in-gc", "TimeInGC"},
            {"alloc-rate", "AllocationRate"},
            {"cpu-usage", "CpuUsage"},
            {"exception-count", "ExceptionCount"},
            {"gc-heap-size", "GCHeapSize"},
            {"working-set", "MemoryWorkingSet"},
        }
    },
    { "Microsoft.AspNetCore.Hosting", new Dictionary<string, string>
        {
            { "requests-per-second", "RequestsPerSecond" },
        }
    }
});
```

{% hint style="info" %}
A full list of well-known performance counters is available at <https://learn.microsoft.com/en-us/dotnet/core/diagnostics/available-counters>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.toggly.io/metrics/metrics-in-c-.net/performance-metrics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
