Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Windows (.NET) library and tools for feeding data into Graphite and statsD.

Current status

Build status

  • Base library (Graphite.dll)
  • Monitoring service for PerformanceCounters (PerfCounterMonitor.exe)
  • Basic instrumentation of ASP.NET MVC apps (inspired by MiniProfiler, Graphite.Mvc.dll)
  • Instrumentation of WCF services (Graphite.Wcf.dll)
  • Sending stats from inside SQL Server using TSQL / a stored procedure (Graphite.TSql.dll)
  • MSBuild task for sending stats to Graphite and StatsD (MSBuild.Graphite.dll)
  • ELMAH error filter for logging all exception to Graphite or StatsD (Graphite.Elmah.dll)

Published NuGet packages


  1. Install NugGet package Graphite (for standalone applications) or Graphite.Wcf for WCF applications or Reference Graphite.Mvc.dll (currently not on NuGet) for ASP.NET MVC applications.

  2. Add configuration for the base Graphite DLL to your App.config/Web.config:

  <section name="graphite" type="Graphite.Configuration.GraphiteConfiguration, Graphite" />
<graphite xmlns="">
  <!--<graphite address="" port="2003" transport="Tcp" />-->
  <statsd address="" port="8125" prefixKey="test" />

It is also possible to set the base configuration inside the connectionStrings section. The graphite "configSection" must not be defined for these connection string configurations to take effect.

  <add name="graphite" connectionString="address=;port=2003;transport=Tcp" />
  <add name="statsd" connectionString="address=;port=8125;prefixKey=test" />
  1. Add a using directive for Graphite: using Graphite;

  2. [For standalone apps] Create a profiler instance on application start: StaticMetricsPipeProvider.Instance.Start(); and stop it on application exit: StaticMetricsPipeProvider.Instance.Stop();.

  3. Use Graphite in your code: MetricsPipe.Current.Count("exception");



The architecture of the Graphite system is inspired by MiniProfiler:

An IMetricsPipeProvider manages the current profiler instance. The implementation of this provider differs depending on the context of the application: ASP.NET/Web, WCF and "standalone"/simple exe file.

Accessing the profiler works always the same through MetricsPipe.Current

Metric Types

There are three different metric types:

  • counter - all values in one flush interval are summed up and submitted as is and as "per second" value by StatsD to the underlying backend (e.g. Graphite) (only for StatsD)
  • timing - all values in one flush interval are aggregated by several statistical operations (mean, upper, lower, ...) (only for StatsD)
  • gauge - for StatsD the latest, reported value is taken, for Graphite the value is reported as is to the Graphite server (for StatsD and Graphite)

Code instrumentation


Reporting metrics to Graphite or StatsD can be done by calling one of the extension methods on MetricsPipe.Current. Therefore a using directive for the Graphite namespace is required:

using Graphite;

The available extension methods correspond to the metric types described in General.


  • void Timing(this MetricsPipe profiler, string key, int value) - for direct submission of timing values
  • IDisposable Step(this MetricsPipe profiler, string key) - for profiling code segements
  • void Count(this MetricsPipe profiler, string key, int value = 1, float sampling = 1) - for reporting counter values
  • void Gauge(this MetricsPipe profiler, string key, int value) - for reporting gauges


  • void Raw(this MetricsPipe profiler, string key, int value) - for directly reporting values to Graphite

An extension method can be called like this:


The Step method is a special method which measures the time till Dispose() is called on the returned IDisposable. This can be done best with a using statement:

using (MetricsPipe.Current.Step("duration"))
    // Do some work here...

The strength of extension methods is that they also work without throwing a NullReferenceException, when MetricsPipe.Current is null - i.e. not initialized.

Standalone Applications

The MetricsPipe can be used in standalone applications (e.g. console or windows applications) after starting the profiler with the following line of code:


Everything is disposed and cleaned up after calling


System Metrics

PerfCounterMonitor.exe (Graphite.System)

Besides profiling and instrumenting your code manually you can report various system parameters to StatsD and Graphite, too. This can be accomplished with the Graphite.System block, respectively PerfCounterMonitor.exe.

Graphite.System enables reporting values from the following sources:

  • Performance counters
  • Event log
  • IIS Application Pools

See the complete documentation for PerfCounterMonitor.exe.

You can download the binaries of Graphite.System here: Graphite.System v1.1.0



WCF services can be instrumented for reporting hit counts and execution times. Therefore an attribute needs to be added to the service instance:

[MetricsPipeBehavior(true, true, fixedRequestTimeKey: null, requestTimePrefix: "service.example", fixedHitCountKey: null, hitCountPrefix: "service.example")]
public class ExampleGraphiteService
    public void Test()

The attribute has the following parameters:

  • bool reportRequestTime - enable reporting of execution time
  • bool reportHitCount - enable reporting of hit counts
  • string fixedRequestTimeKey = null - fixed metric key for execution time metrics
  • string requestTimePrefix = null - prefix key for execution time metrics
  • string fixedHitCountKey = null - fixed metric key for hit count metrics
  • string hitCountPrefix = null - prefix key for hit count metrics

Either the fixed...Key or ...Prefix parameter must be set for an enabled metric.

On setting the fixed...Key parameter, this metric is reported with the specified key as is.

On setting the ...Prefix parameter, this metric is reported with a metric key in the following format:


MSBuild Tasks


Reporting metrics from within MSBuild scripts is possible utilizing the tasks in MSBuild.Graphite.dll

<UsingTask TaskName="MSBuild.Graphite.Tasks.Graphite" AssemblyFile=".\MSBuild.Graphite.dll"></UsingTask>

  <Target Name="graphite">
        Value="1" />



Exceptions captured by ELMAH can be reported using an ELMAH error filter defined in Graphite.Elmah.dll.

This can be accomplished by the following settings in your web.config file:

    <section name="graphite.elmah" type="Graphite.Configuration.GraphiteElmahConfiguration, Graphite.Elmah"/>
    target="statsd" />
            <my:log />

On using the NuGet package Graphite.Elmah all required settings are added to your project automatically during installation.

SQL Server


From within SQL Server, metrics can be reported by calling a stored procedure:

exec sp_graphitesend N'', 2003, '', 1

This stored procedure can be installed using the provided sql script: sp_graphitesend.sql

(see also Sending stats to Graphite from within SQL Server)


  • Instrumentation of ASP.NET MVC applications
  • Montioring log files
  • ...


How to build:

  1. Go to \build directory
  2. Execute go.bat


Windows (.NET) library and tools for feeding data into Graphite and statsD.








No packages published