![]() |
VOOZH | about |
dotnet add package DogStatsD-CSharp-Client --version 9.2.0
NuGet\Install-Package DogStatsD-CSharp-Client -Version 9.2.0
<PackageReference Include="DogStatsD-CSharp-Client" Version="9.2.0" />
<PackageVersion Include="DogStatsD-CSharp-Client" Version="9.2.0" />Directory.Packages.props
<PackageReference Include="DogStatsD-CSharp-Client" />Project file
paket add DogStatsD-CSharp-Client --version 9.2.0
#r "nuget: DogStatsD-CSharp-Client, 9.2.0"
#:package DogStatsD-CSharp-Client@9.2.0
#addin nuget:?package=DogStatsD-CSharp-Client&version=9.2.0Install as a Cake Addin
#tool nuget:?package=DogStatsD-CSharp-Client&version=9.2.0Install as a Cake Tool
A .NET DogStatsD client. DogStatsD is an extension of the StatsD metric server for Datadog.
See for details.
Grab the package from NuGet, or get the source from here and build it yourself.
DogStatsD-CSharp-Client supports the following platforms:
During application startup, configure an instance of DogStatsdService class like this:
// The code is located under the StatsdClient namespace
using StatsdClient;
// ...
var dogstatsdConfig = new StatsdConfig
{
StatsdServerName = "127.0.0.1",
StatsdPort = 8125,
};
using (var service = new DogStatsdService())
{
if (!service.Configure(dogstatsdConfig))
{
throw new InvalidOperationException("Cannot initialize DogStatsD. Set optionalExceptionHandler argument in the `Configure` method for more information.");
}
}
See the full list of available DogStatsD Client instantiation parameters.
Supported environment variables:
DD_AGENT_HOST and (optionally) the DD_DOGSTATSD_PORT environment variables to build the target address if the StatsdServerName and/or StatsdPort parameters are empty.DD_ENTITY_ID environment variable is found, its value will be injected as a global dd.internal.entity_id tag. This tag will be used by the Datadog Agent to insert container tags to the metrics.Where StatsdServerName is the hostname or address of the StatsD server, StatsdPort is the optional DogStatsD port number, and Prefix is an optional string that is prepended to all metrics.
DogStatsdService class or the static DogStatsd classFor usage of DogStatsD metrics, events, and Service Checks the Agent must be running and available.
Here is an example to submit different kinds of metrics with DogStatsdService.
// The code is located under the StatsdClient namespace
using StatsdClient;
// ...
var dogstatsdConfig = new StatsdConfig
{
StatsdServerName = "127.0.0.1",
StatsdPort = 8125,
};
using (var service = new DogStatsdService())
{
if (!service.Configure(dogstatsdConfig))
throw new InvalidOperationException("Cannot initialize DogStatsD. Set optionalExceptionHandler argument in the `Configure` method for more information.");
service.Increment("example_metric.increment", tags: new[] { "environment:dev" });
service.Decrement("example_metric.decrement", tags: new[] { "environment:dev" });
service.Counter("example_metric.count", 2, tags: new[] { "environment:dev" });
var random = new Random(0);
for (int i = 0; i < 10; i++)
{
service.Gauge("example_metric.gauge", i, tags: new[] { "environment:dev" });
service.Set("example_metric.set", i, tags: new[] { "environment:dev" });
service.Histogram("example_metric.histogram", random.Next(20), tags: new[] { "environment:dev" });
System.Threading.Thread.Sleep(random.Next(10000));
}
}
Here is another example to submit different kinds of metrics with DogStatsd.
// The code is located under the StatsdClient namespace
using StatsdClient;
// ...
var dogstatsdConfig = new StatsdConfig
{
StatsdServerName = "127.0.0.1",
StatsdPort = 8125,
};
if (!DogStatsd.Configure(dogstatsdConfig))
{
throw new InvalidOperationException("Cannot initialize DogStatsD. Set optionalExceptionHandler argument in the `Configure` method for more information.");
}
DogStatsd.Increment("example_metric.increment", tags: new[] { "environment:dev" });
DogStatsd.Decrement("example_metric.decrement", tags: new[] { "environment:dev" });
DogStatsd.Counter("example_metric.count", 2, tags: new[] { "environment:dev" });
var random = new Random(0);
for (int i = 0; i < 10; i++)
{
DogStatsd.Gauge("example_metric.gauge", i, tags: new[] { "environment:dev" });
DogStatsd.Set("example_metric.set", i, tags: new[] { "environment:dev" });
DogStatsd.Histogram("example_metric.histogram", random.Next(20), tags: new[] { "environment:dev" });
System.Threading.Thread.Sleep(random.Next(10000));
}
DogStatsd.Dispose(); // Flush all metrics not yet sent
After the client is created, you can start sending custom metrics to Datadog. See the dedicated Metric Submission: DogStatsD documentation to see how to submit all supported metric types to Datadog with working code examples:
Some options are supported when submitting metrics, like applying a Sample Rate to your metrics or Tagging your metrics with your custom Tags.
After the client is created, you can start sending events to your Datadog Event Stream. See the dedicated Event Submission: DogStatsD documentation to see how to submit an event to Datadog Event Stream.
After the client is created, you can start sending Service Checks to Datadog. See the dedicated Service Check Submission: DogStatsD documentation to see how to submit a Service Check to Datadog.
Statsd has been removed in v6.0.0 because it is not thread safe and not efficient. Use DogStatsdService or DogStatsd instead:
DogStatsdService and DogStatsd do not block when called except for Flush and Dispose.DogStatsdService and DogStatsd batch automatically several metrics in one datagram.The version 6 (and above) of the Agent accepts packets through a Unix Socket datagram connection. Details about the advantages of using UDS over UDP are available in the Datadog DogStatsD Unix Socket documentation.
You can use unix domain socket protocol by setting StatsdServerName property to unix://YOUR_FULL_PATH, for example unix:///tmp/dsd.socket. Note that there are three / as the path of the socket is /tmp/dsd.socket.
var dogstatsdConfig = new StatsdConfig
{
StatsdServerName = "unix:///tmp/dsd.socket"
};
The property StatsdMaxUnixDomainSocketPacketSize of StatsdConfig defines the maximum size of the payload. Values higher than 8196 bytes are ignored.
The feature is not supported on Windows platform.
Windows has support for Unix Domain Sockets, but not for Unix Domain Sockets of type Dgram (SocketType.Dgram).
On MacOS Mojave, setting more than 2048 bytes for StatsdMaxUnixDomainSocketPacketSize is experimental.
By default, metrics for basic types (gauges, counts, sets) are aggregated before they are sent. For example, instead of sending my_metric:10|c|#tag1:value 3 times, the DogStatsD client sends my_metric:30|c|#tag1:value once.
For more technical details about how client-side aggregation works see PR #134.
Enabling client-side aggregation has the benefit of reducing network usage and reducing the load for the DogStatsD server in the Datadog Agent.
When an application sends a lot of different contexts but each context appears with a very low frequency, enabling client-side aggregation may take more memory and more CPU. A context identifies a metric name, a tag set, and a metric type. The metric datadog.dogstatsd.client.aggregated_context reported by the DogStatsD .NET client counts the number of contexts in memory used for client-side aggregation. There is also the metric datadog.dogstatsd.client.metrics_by_type that represents the number of metrics submitted by the client before aggregation.
The aggregation window is two seconds by default and can be changed using the FlushInterval. Note that the aggregation window on the Agent side is 10 seconds for DogStatsD metrics. For example, setting an aggregation window of 3s in the client produces a spike in your dashboard every 30s for counts metrics (as the third 10s bucket on the Agent is received 4 samples from the client).
To disable client-side aggregation set ClientSideAggregation to null.
dotnet restore
dotnet test tests/StatsdClient.Tests/
To suggest a feature, report a bug, or general discussion, create a new issue in the GitHub repo.
dogstatsd-csharp-client is forked from Goncalo Pereira's original StatsD client.
Copyright (c) 2012 Goncalo Pereira and all contributors. See LICENSE.md for further details.
Thanks to Goncalo Pereira, Anthony Steele, Darrell Mozingo, Antony Denyer, and Tim Skauge for their contributions to the original client.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 is compatible. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on DogStatsD-CSharp-Client:
| Package | Downloads |
|---|---|
|
AspNetCore.HealthChecks.Publisher.Datadog
HealthChecks.Publisher.Datadog is the health check publisher for Datadog. |
|
|
Serilog.Sinks.Datadog
Package Description |
|
|
Akka.Monitoring.Datadog
Akka.Monitoring extension for reporting to Datadog |
|
|
Ubiquitous.Metrics.Dogstatsd
Package Description |
|
|
CL.Monitoring
Package Description |
Showing the top 4 popular GitHub repositories that depend on DogStatsD-CSharp-Client:
| Repository | Stars |
|---|---|
|
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
|
|
|
PiotrJustyna/road-to-orleans
This repository illustrates the road to orleans with practical, real-life examples. From most basic, to more advanced techniques.
|
|
|
veldtech/miki-bot
Miki Discord Bot
|
|
|
Particular/docs.particular.net
All content for ParticularDocs
|
| Version | Downloads | Last Updated |
|---|---|---|
| 9.2.0 | 12,697 | 6/10/2026 |
| 9.1.0 | 141,337 | 4/28/2026 |
| 9.0.0 | 2,419,431 | 8/18/2025 |
| 8.0.0 | 19,329,896 | 10/27/2022 |
| 7.0.1 | 2,062,107 | 6/28/2022 |
| 7.0.0 | 16,527,893 | 10/13/2021 |
| 6.0.0 | 8,497,272 | 11/23/2020 |
| 5.1.0 | 1,921,738 | 9/8/2020 |
| 5.0.2 | 1,511,006 | 5/29/2020 |
| 5.0.1 | 22,697 | 5/19/2020 |
| 5.0.0 | 36,265 | 5/13/2020 |
| 4.0.1 | 3,829,482 | 2/11/2020 |
| 4.0.0 | 1,663,130 | 1/3/2020 |
| 3.4.0 | 415,793 | 11/15/2019 |
| 3.3.0 | 3,354,861 | 4/5/2019 |
| 3.2.0 | 1,654,829 | 10/18/2018 |
| 3.1.0 | 2,265,308 | 11/16/2017 |
| 3.0.0 | 822,738 | 10/31/2016 |
| 2.2.1 | 78,333 | 10/13/2016 |
See release notes at https://github.com/DataDog/dogstatsd-csharp-client/releases.