https://github.com/dotnetkit/metricflow
MetricFlow is a .NET library designed to help developers define and track functional and domain-oriented metrics (such as counters, timers, and event-based measurements)
https://github.com/dotnetkit/metricflow
csharp-library diagnostics events logging metrics monitoring
Last synced: 11 months ago
JSON representation
MetricFlow is a .NET library designed to help developers define and track functional and domain-oriented metrics (such as counters, timers, and event-based measurements)
- Host: GitHub
- URL: https://github.com/dotnetkit/metricflow
- Owner: DotnetKit
- License: mit
- Created: 2024-12-12T23:23:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-01T21:28:01.000Z (over 1 year ago)
- Last Synced: 2025-08-05T01:47:28.575Z (11 months ago)
- Topics: csharp-library, diagnostics, events, logging, metrics, monitoring
- Language: C#
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MetricFlow



MetricFlow is a lightweight .NET library designed to help developers define and track functional and domain-oriented metrics (such as counters, timers, and event-based measurements).
## Features
- **Counters**: Track the number of occurrences of an event.
- **Timers**: Measure the duration of operations.
- **Event-based Measurements**: Capture and analyze specific events within your application.
- **Metadata and Tags**: Add contextual information to your metrics for better analysis and filtering.
- **Sampling**: Control the frequency of metric collection to manage performance and data volume.
## Getting Started
### Prerequisites
- .NET SDK installed on your machine
### Installation
1. Clone the repository:
```sh
git clone https://github.com/yourusername/DotnetKit.git
cd DotnetKit/MetricFlow
```
2. Restore dependencies:
```sh
dotnet restore
```
### Usage
To use MetricFlow in your project, follow these steps:
1. Define a metric tracker:
```csharp
var tracker = new MetricTracker("ExecutionTimeMetricsTopic", new()
{
["tenant_id"] = "TenantId1",
["session_id"] = Guid.NewGuid().ToString()
});
```
2. Track metrics in different ways:
```csharp
tracker.In("GlobalOperation");
for (var i = 0; i < 10; i++)
{
using (var __ = tracker.Track("Operation1", new() { ["operation_id"] = $"{i}" }))
{
await Task.Delay(2);
}
using (var __ = tracker.Track("Operation2", new() { ["operation_id"] = $"{10 - i}" }))
{
await Task.Delay(4);
}
}
tracker.Out("GlobalOperation");
Console.WriteLine(tracker.ToString());
```
### Example
The `SimpleMetricCountersExample` demonstrates how to use the `MetricFlow` library to track and measure metrics in a .NET application. The example includes a `BenchRunner` class that simulates operations and tracks their execution times.
### Running the Example
To run the example, execute the following command:
```sh
dotnet run --project examples/SimpleMetricCountersExample