AppMetrics.Grpc.AspNetCore 1.0.0

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

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

AppMetrics.Grpc.AspNetCore

Provides an interceptor that can be used to track 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.

Usage

Add interceptor when registering code-first services:

using AppMetrics.Grpc.AspNetCore.Interceptors;

public void ConfigureServices(IServiceCollection services)
{
    services.AddCodeFirstGrpc(config =>
    {
        config.ResponseCompressionLevel = System.IO.Compression.CompressionLevel.Optimal;
        config.Interceptors.Add<MetricsInterceptor>();
    });
}

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:

using AppMetrics.Grpc.AspNetCore.HostedServices;
using App.Metrics;
using App.Metrics.AspNetCore;
using App.Metrics.Formatters.Json;
using App.Metrics.Formatters.Prometheus;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System.Linq;

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)
            .UseMetrics()
            .AddMetricsServer(metrics, endpointsOptions =>
            {
                endpointsOptions.MetricsEndpointOutputFormatter = metrics.OutputMetricsFormatters.OfType<MetricsJsonOutputFormatter>().First();
                endpointsOptions.MetricsTextEndpointOutputFormatter = metrics.OutputMetricsFormatters.OfType<MetricsPrometheusTextOutputFormatter>().First();
                endpointsOptions.EnvironmentInfoEndpointEnabled = false;
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
    }
}

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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,672 5/18/2022
2.0.1 399 5/17/2022
2.0.0 361 5/17/2022
1.0.2 493 3/2/2022
1.0.1 405 3/2/2022
1.0.0 396 3/1/2022