adsurg / splunk.metrics

Extended metrics using statsd for Splunk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Splunk extended metrics (using statsd)

Build Status

FAQ

  • Why did you create yet another statsd client especially for Splunk?

Splunk supports expanded statsd metrics. This library supports dimensions and sample rates.

Definging your statsd metric bucket namespace

The statsd bucket consists of 6 parts

  • The first and second are the feature and action eg order-processor.orders, ingestion.entities
  • The sixth is the event (and should be defined in the past as a fact) eg succeeded, failed, processed, etc

The following are examples of the full statsd string generated if you follow this guideline:

order-processor.orders.processed
ingestion.entities.handled

How to add metrics to your code

  • Install the Nuget package Splunk.Metrics.Abstractions
Install-Package Splunk.Metrics.Abstractions
  • Inject IStatsPublisher from the installed library and call the methods for counts, gauges and timing
public class Foo
{
   Foo(IStatsPublisher statsPublisher)
   {
      this.statsPublisher = statsPublisher;
   }

   public async Task DoSomething()
   {
      await statsPublisher.IncrementAsync("order-processor.orders.processed");
   }
}

Bootstrapping .NET Core Applications

  • Install the Nuget package Splunk.Metrics.Statsd
Install-Package Splunk.Metrics.Statsd
  • In your startup or bootstrapper:
serviceCollection.AddTransient<IStatsPublisher, StatsPublisher>();
serviceCollection.Configure<MetricsConfiguration>(configuration.GetSection("Stats"));
  • In your appsettings file, define the namespace
"Stats": {
    "Prefix": "some-product.some-service" 
}

Bootstrapping Legacy Full .NET Applications

  • Install the Nuget package Splunk.Metrics.Statsd
Install-Package Splunk.Metrics.Statsd
  • In your startup or bootstrapper:
container.RegisterType<IStatsPublisher, StatsPublisher>();
container.RegisterInstance(new StatsConfiguration(...)));
  • In your appsettings file, define the namespace
"Stats": {
    "Prefix": "some-product.some-service"
}

Adding HTTP Metrics

  • Install the Nuget package Splunk.Metrics.Http
Install-Package Splunk.Metrics.Http
  • In your startup, add the HTTP metrics middleware to the OWIN pipeline. Note that this should be one of the first middlewares in the pipeline to effectively capture metrics for all requests:
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseHttpMetrics();
            app.UseMvc();
        }

About

Extended metrics using statsd for Splunk


Languages

Language:C# 100.0%