Giter VIP home page Giter VIP logo

graphite-client's Introduction

graphite-client

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

Current 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

Features/Documentation

General

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

Graphite.dll

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.

StatsD:

  • 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

Graphite:

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

An extension method can be called like this:

MetricsPipe.Current.Count("exception");

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:

StaticMetricsPipeProvider.Instance.Start();

Everything is disposed and cleaned up after calling

StaticMetricsPipeProvider.Instance.Stop();

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.

WCF

Graphite.Wcf.dll

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

[ServiceBehavior]
[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:

[prefixKey].[servicename].[operation_name]

MSBuild Tasks

MSBuild.Graphite.dll

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">
    <MSBuild.Graphite.Tasks.Graphite
        Address="192.168.2.100"
        Transport="Tcp"
        PrefixKey="stats.events"
        Key="deploys.test"
        Value="1" />
  </Target>

ELMAH

Graphite.Elmah.dll

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:

<configSections>
    <section name="graphite.elmah" type="Graphite.Configuration.GraphiteElmahConfiguration, Graphite.Elmah"/>
</configSections>
<graphite.elmah
    xmlns="http://github.com/peschuster/Graphite/Configuration"
    key="elmah_errors"
    type="counter"
    target="statsd" />
<elmah>
    <errorFilter>
        <test
            xmlns:my="http://schemas.microsoft.com/clr/nsassem/Graphite/Graphite.Elmah">
            <my:log />
        </test>
    </errorFilter>
</elmah>

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

SQL Server

Graphite.TSql.dll

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

exec sp_graphitesend N'192.168.0.1', 2003, 'stats.events.myserver.test', 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)

TODO

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

Building...

How to build:

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.