A simple Graphite client library for .NET, including a WCF behavior for measuring duration of service operation calls.
A client for StatsD is also included.
// Import namespaceusingGraphite;// ...// Create an UDP client for sending metrics to "localhost:2003", prefixing all keys with "foo.bar"using(varclient=newGraphiteUdpClient("localhost",2003,"foo.bar")){// Report a metricclient.Send("baz",93284928374);// Report a metric specifying timestampclient.Send("baz",93284928374,DateTime.Now.AddSeconds(42));}// Import namespaceusingGraphite.StatsD;// ...// Create a client for sending metrics to "localhost:8125", prefixing all keys with "foo.bar"using(varclient=newStatsDClient("localhost",8125,"foo.bar")){// Increment a counterclient.Incremenet("counter1");// sends 'foo.bar.counter1:1|c'// Increment a counter by 42client.Incremenet("counter2",42);// sends 'foo.bar.counter2:42|c'// Decrement a counter by 5, sampled every 1/10th timeclient.Decrement("counter3",5,0.1);// sends 'foo.bar.counter3:-5|c@0.1// Report that the blahonga operation took 42 msclient.Timing("blahonga",42);// sends 'foo.bar.blahonga:42|ms'}Also included with Graphite.NET is a WCF endpoint behavior that measures and reports the duration of service operation invocations.
Currently only support for StatsD is implemented.
To use the behavior, first register it as an behavior extension, then use
it in suitable endpointBehavior elements.
The behavior will time all service operation invocations, sending metrics on
the form KeyPrefix.ContractName.OperationName.
Example configuration:
<system.serviceModel>
<!-- Register behavior extension -->
<extensions>
<behaviorExtensions>
<addname="timeOperations"type="Graphite.WCF.OperationTimingEndpointBehaviorExtensionElement, Graphite" />
</behaviorExtensions>
</extensions>
<!-- Use the behavior where suitable -->
<behaviors>
<endpointBehaviors>
<behaviorname="...">
<timeOperationshostname="..."port="..."keyPrefix="..." />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel> The OperationTimingEndpointBehaviorExtensionElement has three attributes:
hostname(required): address to StatsD instanceport(optional, default is 8125): the port StatsD is listening onkeyPrefix(optional, default is none): namespace to prefix keys with