Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AccumulationsConsumer now accepts a regular expression to limit it to…

… a subset of Graphite targets.
  • Loading branch information...
commit 483b9a2c99ffdccd1f422f60ed0c683d87f53be9 1 parent 7acb021
Dhruv Bansal dhruvbansal authored
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/graphiterb/monitors/accumulations_consumer.rb
12 lib/graphiterb/monitors/accumulations_consumer.rb
View
@@ -11,15 +11,26 @@ class AccumulationsConsumer < Graphiterb::Monitors::PeriodicMonitor
# The Redis namespace used for the accumulators.
attr_accessor :accumulators
+ # A regular expression that must match the Graphite target
+ # (defaults to always matching).
+ attr_accessor :regexp
+
# Instantiate a new AccumulationsConsumer.
#
# Options are passed to Redis.new as well as
# Graphiterb::Monitors::PeriodicMonitor.
+ #
+ # Include the :regexp option if you want this monitor to only
+ # consume keys corresponding to Graphite targets which match the
+ # regexp. This is useful for having multiple
+ # AccumulationsConsumer monitors running with different
+ # frequencies tracking different Graphite target families.
def initialize options={}
require 'redis'
require 'redis-namespace'
@redis = Redis.new(options)
@accumulators = Redis::Namespace.new('graphiterb_accumulators', :redis => @redis)
+ @regexp = options[:regexp] || /.*/
super('fake_scope', options)
end
@@ -27,6 +38,7 @@ def initialize options={}
# from Redis and reset them to 0 atomically.
def get_metrics metrics, since
accumulators.keys.each do |target|
+ next unless regexp =~ target
current_count = accumulators.getset(target, 0) rescue 0.0
rate = current_count.to_f / since.to_f rescue 0.0
metrics << [target, rate] # no need to scope as targets are pre-scoped
Please sign in to comment.
Something went wrong with that request. Please try again.