lib/logstash/outputs/dogstatsd.rb in logstash-output-dogstatsd-1.2.0 vs lib/logstash/outputs/dogstatsd.rb in logstash-output-dogstatsd-1.3.0
- old
+ new
@@ -27,13 +27,11 @@
#
# Example:
# [source,ruby]
# output {
# dogstatsd {
-# metric_tags => {
-# "host" => "%{host}"
-# }
+# metric_tags => ["host:%{host}","role:foo"]
# count => {
# "http.bytes" => "%{bytes}"
# }
# }
# }
@@ -69,11 +67,11 @@
# The sample rate for the metric.
config :sample_rate, :validate => :number, :default => 1
# The tags to apply to each metric.
- config :metric_tags, :validate => :hash, :default => {}
+ config :metric_tags, :validate => :array, :default => []
public
def register
@client = Datadog::Statsd.new(@host, @port)
end # def register
@@ -81,12 +79,14 @@
public
def receive(event)
return unless output?(event)
@logger.debug? and @logger.debug("Event: #{event}")
- tags = process_tags(event, @metric_tags)
- metric_opts = { :sample_rate => @sample_rate, :tags => tags }
+ metric_opts = {
+ :sample_rate => @sample_rate,
+ :tags => @metric_tags.map { |t| event.sprintf(t) }
+ }
@increment.each do |metric|
@client.increment(event.sprintf(metric), metric_opts)
end
@@ -108,12 +108,6 @@
@gauge.each do |metric, val|
@client.gauge(event.sprintf(metric), event.sprintf(val), metric_opts)
end
end # def receive
-
- private
- # Returns an array of tags like ["tag1:value1", "tag2:value2"]
- def process_tags(event, tags)
- tags.map { |k, v| event.sprintf(k) + ':' + event.sprintf(v) }
- end
end # class LogStash::Outputs::Statsd