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
<PackageReference Include="AppMetrics.Grpc.AspNetCore" Version="2.0.2" />
paket add AppMetrics.Grpc.AspNetCore --version 2.0.2
#r "nuget: AppMetrics.Grpc.AspNetCore, 2.0.2"
// 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
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 | Versions 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. |
-
.NETCoreApp 3.1
- App.Metrics.AspNetCore (>= 4.3.0)
- App.Metrics.Formatters.Prometheus (>= 4.3.0)
- Grpc.AspNetCore.Server (>= 2.46.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Options (>= 6.0.0)
-
net6.0
- App.Metrics.AspNetCore (>= 4.3.0)
- App.Metrics.Formatters.Prometheus (>= 4.3.0)
- Grpc.AspNetCore.Server (>= 2.46.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Options (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.