DotnetKit.MetricFlow 1.0.0-preview.0.6

This is a prerelease version of DotnetKit.MetricFlow.
dotnet add package DotnetKit.MetricFlow --version 1.0.0-preview.0.6
                    
NuGet\Install-Package DotnetKit.MetricFlow -Version 1.0.0-preview.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotnetKit.MetricFlow" Version="1.0.0-preview.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotnetKit.MetricFlow" Version="1.0.0-preview.0.6" />
                    
Directory.Packages.props
<PackageReference Include="DotnetKit.MetricFlow" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotnetKit.MetricFlow --version 1.0.0-preview.0.6
                    
#r "nuget: DotnetKit.MetricFlow, 1.0.0-preview.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotnetKit.MetricFlow@1.0.0-preview.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotnetKit.MetricFlow&version=1.0.0-preview.0.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=DotnetKit.MetricFlow&version=1.0.0-preview.0.6&prerelease
                    
Install as a Cake Tool

MetricFlow

internal public Dotnetkit.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:

    git clone https://github.com/yourusername/DotnetKit.git
    cd DotnetKit/MetricFlow
    
  2. Restore dependencies:

    dotnet restore
    

Usage

To use MetricFlow in your project, follow these steps:

  1. Define a metric tracker:

    var tracker = new MetricTracker("ExecutionTimeMetricsTopic", new()
    {
        ["tenant_id"] = "TenantId1",
        ["session_id"] = Guid.NewGuid().ToString()
    });
    
  2. Track metrics in different ways:

    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:

dotnet run --project examples/SimpleMetricCountersExample
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.0.6 81 2/26/2025