lib/metricize/client.rb in metricize-0.4.5 vs lib/metricize/client.rb in metricize-0.4.6
- old
+ new
@@ -2,10 +2,11 @@
class Client
include SharedMethods
def initialize(options = {})
@prefix = options[:prefix]
+ @sampling_ratio = options[:sampling_ratio] || 0.10
establish_logger(options)
initialize_redis(options)
establish_redis_connection
end
@@ -37,13 +38,16 @@
push_to_queue(build_metric_name(name), round(value, 4), options)
end
def push_to_queue(name, value, options)
data = prepare_metric(name, value, options).to_json
- @redis.lpush(@queue_name, data)
+ with_error_handling do
+ @redis.lpush(@queue_name, data)
+ end
+ return unless rand < @sampling_ratio
msg = "#{name.gsub('.', '_')}=#{value}" # splunk chokes on dots in field names
msg << ", metric_source=#{options[:source].gsub('.', '_')}" if options[:source]
- log_message msg
+ log_message msg, :info
end
def build_metric_name(name)
[ @prefix, sanitize(name) ].compact.join('.')
end