Repository is archived
No commit activity in last 3 years
No release in over 3 years
Applies a source prefix to any custom source names supplied when submitting metrics
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0

Runtime

 Project Readme

librato-rack-source_prefix

Gem Version Build Status

This gem enables the automatic prefixing of metric source names.

By default, when you submit a metric with a custom source, that source will be passed as-is to the Librato API. For example:

Librato.increment :foo, source: "my.source"

The code above would result in the following data being POSTed to the Librato API:

{
  "gauges": [ 
    {
      "name": "foo",
      "value": 1, 
      "source": "my.source"
    }
  ]
}

Note that the source passed to the API is identical to the value specified in the increment call. Even if you had configured a global source value (either via the LIBRATO_SOURCE environment variable or the librato.yml configuration file) the global source value is ignored completely.

If you were to configure a global source value of myapp and install the librato-rack-source_prefix gem, the same code shown above would result in the following data being POSTed:

{
  "gauges": [ 
    {
      "name": "foo",
      "value": 1, 
      "source": "myapp.my.source"
    }
  ]
}

In this case, the source value specified as part of the increment call is automatically prefixed with the global source myapp.

To override this behavior and preserve the source name, use the apply_prefix option:

Librato.increment :foo, source: "my.source", apply_prefix: false

Installation

Add this line to your application's Gemfile:

gem 'librato-rack-source_prefix'

And then execute:

$ bundle

Or install it yourself as:

$ gem install librato-rack-source_prefix

If you are using the librato-rails gem, add this line to your librato.yml:

source_prefix: one.prefix.to.rule.them.all

Rack Applications

If your application is using a non-Rails, Rack framework you'll need to add the following line to your app in order to enable the source prefixing behavior:

  Librato::Collector.include(Librato::Rack::SourcePrefix::Extensions::Collector)

You'll want to add this line wherever you've configured your Librato::Rack middleware.

Rails

If you are using Rails, source prefixing will be enabled automatically as a result of adding the librato-rack-source_prefix gem to your Gemfile. No additional configuration is required.

Copyright

Copyright (c) 2015 Librato Inc. See LICENSE for details.