AppMetrics.Grpc.AspNetCore 2.0.2

dotnet add package AppMetrics.Grpc.AspNetCore --version 2.0.2
NuGet\Install-Package AppMetrics.Grpc.AspNetCore -Version 2.0.2
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="AppMetrics.Grpc.AspNetCore" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AppMetrics.Grpc.AspNetCore --version 2.0.2
#r "nuget: AppMetrics.Grpc.AspNetCore, 2.0.2"
#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 AppMetrics.Grpc.AspNetCore as a Cake Addin
#addin nuget:?package=AppMetrics.Grpc.AspNetCore&version=2.0.2

// Install AppMetrics.Grpc.AspNetCore as a Cake Tool
#tool nuget:?package=AppMetrics.Grpc.AspNetCore&version=2.0.2

AppMetrics.Grpc.AspNetCore

Build status NuGet License

Provides an interceptor that can be used to track Grpc.AspNetCore and protobuf-net.Grpc.AspNetCore endpoint calls using App.Metrics.AspNetCore.Tracking middleware components.

A standalone MetricsServer is provided to help expose the metrics on a separate port.

Installation

Add the package to your application using

dotnet add package AppMetrics.Grpc.AspNetCore

Usage with Minimal APIs

Add grpc metrics before http metrics:

using AppMetrics.Grpc.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

var metrics = App.Metrics.AppMetrics.CreateDefaultBuilder()
    .OutputMetrics.AsPrometheusPlainText()
    .Build();

builder.WebHost
    .ConfigureMetrics(metrics)
    .UseGrpcMetrics()
    .UseMetrics();

Usage without Minimal APIs

Add grpc metrics before http metrics:

using AppMetrics.Grpc.AspNetCore;

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) {
        var metrics = App.Metrics.AppMetrics.CreateDefaultBuilder()
            .OutputMetrics.AsPrometheusPlainText()
            .Build();

        return Host.CreateDefaultBuilder(args)
            .ConfigureMetrics(metrics)
            .UseGrpcMetrics()
            .UseMetrics()
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
    }
}

Usage of standalone MetricsServer

To expose metrics on a different port using the MetricsServer call AddMetricsServer either on a IHostBuilder or a IWebHostBuilder and pass the same IMetricsRoot instance used in the main host:

builder.WebHost
    .ConfigureMetrics(metrics)
    .UseGrpcMetrics()
    .UseMetrics()
    .AddMetricsServer(metrics, endpointsOptions =>
    {
        endpointsOptions.MetricsEndpointOutputFormatter = metrics.OutputMetricsFormatters.OfType<MetricsJsonOutputFormatter>().First();
        endpointsOptions.MetricsTextEndpointOutputFormatter = metrics.OutputMetricsFormatters.OfType<MetricsPrometheusTextOutputFormatter>().First();
        endpointsOptions.EnvironmentInfoEndpointEnabled = false;
    });

Configuration

Optionally add the following configuration to your appsettings.json

"MetricsServerOptions": {
  "EnvironmentInfoEndpoint": "/env",
  "MetricsEndpoint": "/metrics",
  "MetricsTextEndpoint": "/metrics-text",
  "Port": 5501
}

By default the MetricsServer will listen on port 5501 on all interfaces.

Grafana

The following dashboard can be used to view the exported metrics in Grafana: https://grafana.com/grafana/dashboards/15840

License

The source code and documentation in this project are released under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.1 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
2.0.2 1,658 5/18/2022
2.0.1 398 5/17/2022
2.0.0 360 5/17/2022
1.0.2 489 3/2/2022
1.0.1 401 3/2/2022
1.0.0 395 3/1/2022