Class MetricsOptions
Specifies options for a NeonService. This is initialized to reasonable defaults.
Namespace: Neon.Service
Assembly: Neon.Service.dll
Syntax
public class MetricsOptions
Remarks
These options allow developers to customize some service behaviors. This is is exposed as the MetricsOptions property and is initialized to reasonable default values. Developers may modify these options as desired before calling RunAsync(bool) to start their service.
Prometheus metrics capturing is disabled by default. You can change this by setting Mode to Scrape, ScrapeIgnoreErrors, or Push. The two scrape modes expect that Prometheus will be perodically reading metrics from the service via the HTTP endpoint specified by Port and Path.
note
The ScrapeIgnoreErrors mode is somewhat specialized and is intended for testing environments and is not recommended for production.
note
Built-in Prometheus scraping support is limited to HTTP and not HTTPS and no authentication is enforced. Pushgateway support can use HTTPS as well as HTTP, but we don't support authentication at this time.
For more complex scenarios, just leave Mode==
Disabled
and configure prometheus-net yourself before calling RunAsync(bool). We're
trying to address 80% scenarios to reduce a bit of service related boilerplate code but prometheus-net
is quite easy to configure.
.NET CORE RUNTIME METRICS
For .NET Core apps, you'll also need to add a reference to the prometheus-net.DotNetRuntime nuget package and set GetCollector to a function that returns the the collector to be used. This will look like:
Service.MetricsOptions.GetCollector =
() =>
{
return DotNetRuntimeStatsBuilder
.Default()
.StartCollecting();
};
ASPNETCORE METRICS:
For ASPNETCORE metrics, you'll need to add the prometheus-net.AspNetCore nuget package and then add the collector when configuring your application in the Startup class, like:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseHttpMetrics(); // <--- add this
}
Properties
GetCollector
Optionally configures a callback that can return a custom metrics collector for the service.
For non-ASPNETCORE applications, we recommend that you configure this to return the standard .NET Runtime metrics collector so your services will report those as well. You'll need to install the prometheus-net.DotNetRuntime nugeyt package and the code to configure looks like this:
Service.MetricsOptions.GetCollector =
() =>
{
return DotNetRuntimeStatsBuilder
.Default()
.StartCollecting();
};
For ASP.NET applications, we recommend that you add metrics collection middleware by adding
the Prometheus.AspNetCore nuget package and configure your middleware in your Startup
class like:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpMetrics(); // <-- Enable ASPNETCORE metrics
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Declaration
public Func<IDisposable> GetCollector { get; set; }
Property Value
Type | Description |
---|---|
Func<IDisposable> |
Mode
Enables Prometheus and controls how metrics are published.
Declaration
public MetricsMode Mode { get; set; }
Property Value
Type | Description |
---|---|
MetricsMode |
Path
Specifies the URL path for the local HTTP listener that exposes metrics for scraping by Prometheus. This defaults to "metrics/".
Declaration
public string Path { get; set; }
Property Value
Type | Description |
---|---|
string |
Port
Specifies the TCP port for the local HTTP listener that exposes metrics for scraping by Prometheus. This defaults to PrometheusMetrics.
Declaration
public int Port { get; set; }
Property Value
Type | Description |
---|---|
int |
PushInterval
Specifies how often metrics will be pushed to the target Prometheus Pushgateway for Push mode. This defaults to 5 seconds.
Declaration
public TimeSpan PushInterval { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
PushLabels
Optionally specifies additional labels to be identify the source for Push mode.
Declaration
public IList<Tuple<string, string>> PushLabels { get; set; }
Property Value
Type | Description |
---|---|
IList<Tuple<string, string>> |
PushUrl
Specifies the target Prometheus Pushgateway for Push mode.
This defaults to null
.
Declaration
public string PushUrl { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
Validate()
Validates the options.
Declaration
public void Validate()
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown for any errors. |