NimblePros.Metronome 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NimblePros.Metronome --version 0.1.0                
NuGet\Install-Package NimblePros.Metronome -Version 0.1.0                
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="NimblePros.Metronome" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NimblePros.Metronome --version 0.1.0                
#r "nuget: NimblePros.Metronome, 0.1.0"                
#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.
// Install NimblePros.Metronome as a Cake Addin
#addin nuget:?package=NimblePros.Metronome&version=0.1.0

// Install NimblePros.Metronome as a Cake Tool
#tool nuget:?package=NimblePros.Metronome&version=0.1.0                

Metronome by NimblePros

A simple tool for tracking Database and Http calls per ASP.NET Core request.

Installation

Install the NuGet package:

Install-Package NimblePros.Metronome

dotnet add package NimblePros.Metronome

Usage

Refer to the samples in the samples directory.

Wire up services

builder.Services.AddMetronome();

Add Middleware

Add the middleware near the top of the pipeline. Recommended to be used only in development environment.

if (app.Environment.IsDevelopment())
{
  app.UseMetronomeLoggingMiddleware();
}

EF Core Query Tracking

builder.Services.AddDbContext<ApplicationDbContext>((provider, options) =>
    options.UseSqlite(connectionString) // or any other provider
        .AddInterceptors(provider.GetRequiredService<DbCallCountingInterceptor>())
    );

HttpClient Tracking

// simple named client
builder.Services.AddHttpClient("Foo")
    .AddMetronomeHandler();

// strongly typed client
builder.Services.AddScoped<IPostsService, PostsService>(); // interface is optional
builder.Services.AddHttpClient<IPostsService, PostsService>()
    .ConfigureHttpClient(client =>
    {
      client.BaseAddress = new Uri("https://my-json-server.typicode.com/typicode/demo/");
    })
    .AddMetronomeHandler();

Expected Output

When hitting individual pages or endpoints, you should see the following output in the console:

info: NimblePros.Metronome.CombinedCallLoggingMiddleware[0]
      Database calls: 2, Total time: 6.4678 ms
info: NimblePros.Metronome.CombinedCallLoggingMiddleware[0]
      HTTP calls: 1, Total time: 222.3137 ms

You can use this to identify slow pages or endpoints and optimize them by adding caching, combining queries, or reducing the number of HTTP calls.

If you need help doing this in an effective way across your entire application, contact NimblePros. We do this all the time.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.4.0 38 12/20/2024
0.2.0 37 12/18/2024
0.1.0 43 12/18/2024

* Initial release