A simple c# client library for statsd.net and statsd.
Coming soon:
Install the StatsdCsharpClient via nuget:
PM> Install-Package StatsdCsharpClient
Assuming your server is running on localhost and listening on port 12000:
using StatsdClient;
...
var statsd = new Statsd("localhost", 12000);
// Log a count
statsd.LogCount( "site.hits" );
// Log a gauge
statsd.LogGauge( "site.activeUsers", numActiveUsers );
// Log a timing
statsd.LogTiming( "site.pageLoad", 100 /* milliseconds */ );
// Log a raw metric
statsd.LogRaw ("already.aggregated", 982, 1885837485 /* epoch timestamp */ );
// Log a calendargram
statsd.LogCalendargram("order.completed", "user_13143", CalendargramRetentionPeriod.HOUR);
You can also wrap your code in a using
block to measure the latency by using the LogTiming(string) extension method:
using StatsdClient;
...
using (statsd.LogTiming( "site.db.fetchReport" ))
{
// do some work
}
// At this point your latency has been sent to the server
There's also a nifty set of extension methods that let you define your stats without using strings. Using the example provided above, but now using the builder:
var statsd = new StatsdClient("localhost", 12000);
// Log a count
statsd.count.site.hits += 1;
// Log a gauge
statsd.gauge.site.activeUsers += numActiveUsers;
// Log a timing
statsd.site.pageLoad += 100; /* milliseconds */
Metrics can be delivered over a TCP connection by specifying ConnectionType.Tcp during construction:
var statsd = new Statsd("localhost", 12001);
// Continue as normal
The connection will attempt to reconnect if something goes wrong, and will try three times before giving up. Use the retryOnDisconnect parameter to enable/disable this, and the retryAttempts parameter to specify the number of times to try the request again.
Luke Venediger - lukev@lukev.net and @lukevenediger