On one project we use Graphite and StatsD to monitor some webserver and performance parameters of the site and ELMAH to catch all unhandled exceptions. Wouldn’t it be cool to also see the occurrence of exceptions captured by ELMAH in our Graphite graphs?
For this purpose I extended my library of Graphite “tools” by a Graphite.Elmah project.
ELMAH is designed to support only on backend for logging errors. This is usually configured to be some kind of database backend to store exception details for later access. Therefore Graphite.Elmah hooks into ELMAH using a custom error filter, to report exceptions to Graphite or StatsD.
You can configure ELMAH in your project to use this error filter with the following configuration snipped:
<errorFilter> <test xmlns:my="http://schemas.microsoft.com/clr/nsassem/Graphite/Graphite.Elmah"> <my:log /> </test> </errorFilter>
Graphite.Elmah itself needs to be configured with the following settings:
<graphite.elmah key="elmah_errors" type="counter" target="statsd" />
You can set a metric key, a metric type and a target for the metrics (either “statsd” or “graphite”). The complete configuration for your web.config file is also included in the respective readme for reference: Graphite.Elmah web.config
Graphite.Elmah was build upon the Graphite base library. Therefore some configuration for the Graphite backend(s) is required as well:
<configSections> <section name="graphite" type="Graphite.Configuration.GraphiteConfiguration, Graphite" /> </configSections> <graphite xmlns="http://github.com/peschuster/Graphite/Configuration"> <!--<graphite address="127.0.0.1" port="2003" transport="Tcp" />--> <statsd address="127.0.0.1" port="8125" prefixKey="test" /> </graphite>
When using the NuGet package Graphite.Elmah all required settings are added to your project automatically during installation: