Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow selection of which metrics to submit from Librato metrics reporter #9

Open
wants to merge 1 commit into from

3 participants

@ryanlower

Can specific :only or :except when initializing the reporter, e.g.

Metriks::Reporter::LibratoMetrics.new(
  'email',
  'key',
  {
    prefix: 'example',
    only: [
      :count,
      :mean,
      :one_minute_rate
    ]
  }
).start
@eric
Owner

This is great. It may be a couple days before I get a chance to merge and release this — I'm traveling in Japan at the moment... but this looks useful.

Thanks for the pull request.

@eric eric commented on the diff
lib/metriks/reporter/librato_metrics.rb
@@ -12,6 +12,12 @@ def initialize(email, token, options = {})
@registry = options[:registry] || Metriks::Registry.default
@interval = options[:interval] || 60
@on_error = options[:on_error] || proc { |ex| }
+
+ if options[:only] and options[:except]
+ raise 'Can only specify one of :only or :except'
+ end
+ @only = options[:only] || []
+ @except = options[:except] || []
@eric Owner
eric added a note

Defaulting these to an empty array is going to cause the if's later on to always evaluate to true.

I think this may be worth a test case to not break things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@theDoug

This one is going to really come in handy. Thanks guys!

@eric eric commented on the diff
lib/metriks/reporter/librato_metrics.rb
@@ -121,6 +127,15 @@ def prepare_metric(base_name, metric, keys, snapshot_keys = [])
base_name = "#{@prefix}.#{base_name}"
end
+ if @only
@eric Owner
eric added a note

With the defaulting above, this is going to need to be if @only && !@only.empty? — same with the @except one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/metriks/reporter/librato_metrics.rb
View
15 lib/metriks/reporter/librato_metrics.rb
@@ -12,6 +12,12 @@ def initialize(email, token, options = {})
@registry = options[:registry] || Metriks::Registry.default
@interval = options[:interval] || 60
@on_error = options[:on_error] || proc { |ex| }
+
+ if options[:only] and options[:except]
+ raise 'Can only specify one of :only or :except'
+ end
+ @only = options[:only] || []
+ @except = options[:except] || []
@eric Owner
eric added a note

Defaulting these to an empty array is going to cause the if's later on to always evaluate to true.

I think this may be worth a test case to not break things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
end
def start
@@ -121,6 +127,15 @@ def prepare_metric(base_name, metric, keys, snapshot_keys = [])
base_name = "#{@prefix}.#{base_name}"
end
+ if @only
@eric Owner
eric added a note

With the defaulting above, this is going to need to be if @only && !@only.empty? — same with the @except one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ keys = keys & @only
+ snapshot_keys = snapshot_keys & @only
+ end
+ if @except
+ keys = keys - @except
+ snapshot_keys = snapshot_keys - @except
+ end
+
keys.flatten.each do |key|
name = key.to_s.gsub(/^get_/, '')
value = metric.send(key)
Something went wrong with that request. Please try again.