The App.Metrics.StatsD nuget package reports metrics to StatsD using the App.Metrics.Formatting.StatsD and App.Metrics.Reporting.StatsD nuget packages to format and report metrics.
To use the Datadog HTTP reporter, first install the nuget package:
nuget install App.Metrics.StatsD
Then enable the reporter using Report.ToStatsDTcp(...)
:
var metrics = new MetricsBuilder()
.Report.ToStatsDTcp(options => {})
.Build();
or using Report.ToStatsDUdp(...)
:
var metrics = new MetricsBuilder()
.Report.ToStatsDUdp(options => {})
.Build();
See Reporting for details on configuring metric report scheduling.
There are several flavors of StatsD available. App.Metrics.StatsD
currently supports the original Etsy and DogStatsD variants of StatsD, DogStatsD is a StatsD variant that is used to report StatsD metrics to DataDog; by default, the Etsy variant is used.
Timer metrics are not natively supported by DogStatsD. Replace timer metric with histogram if you have to send a timer-like StatsD metric to DogStatsD ingress endpoint.
To change the default formatter to DogStatsD, change the formatter in the options:
var metrics = new MetricsBuilder()
.Report.ToStatsDTcp(
options => {
options.StatsDOptions.MetricNameFormatter = new DefaultDogStatsDMetricStringSerializer();
})
.Build();
Configuration options are provided as a setup action used with ToStatsDTcp(...)
and ToStatsDUdp(...)
.
To configure StatsD reporting options:
var filter = new MetricsFilter().WhereType(MetricType.Timer);
var metrics = new MetricsBuilder()
.Report.ToStatsDTcp(
options => {
options.StatsDOptions.MetricNameFormatter = new DefaultStatsDMetricStringSerializer();
options.StatsDOptions.DefaultSampleRate = 1.0;
options.StatsDOptions.TagMarker = '#';
options.SocketPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
options.SocketPolicy.FailuresBeforeBackoff = 5;
options.SocketPolicy.Timeout = TimeSpan.FromSeconds(10);
options.SocketSettings.Address = "localhost";
options.SocketSettings.Port = 8125;
options.Filter = filter;
})
.Build();
The configuration options provided are:
Option | Description |
---|---|
StatsDOptions.MetricNameFormatter | The metric payload formatter used when reporting StatsD metrics. There are 2 built-in formatter provided, DefaultStatsDMetricStringSerializer and DefaultDogStatsDMetricStringSerializer |
StatsDOptions.DefaultSampleRate | The sample rate used to send metrics that supports them. |
StatsDOptions.TagMarker | The character used to mark the start of tag section for reporters that supports metric tagging. |
Filter | The filter used to filter metrics just for this reporter. |
SocketPolicy.BackoffPeriod | The TimeSpan to back-off when metrics are failing to report to the metrics ingress endpoint. |
SocketPolicy.FailuresBeforeBackoff | The number of failures before backing-off when metrics are failing to report to the metrics ingress endpoint. |
SocketPolicy.Timeout | The socket timeout duration when attempting to report metrics to the metrics ingress endpoint. |
SocketSettings.Address | The socket address of the metrics ingress endpoint. |
SocketSettings.Port | The socket port of the metrics ingress endpoint. |