Class: LogStash::Outputs::Dogstatsd

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/dogstatsd.rb

Overview

dogstatsd is a fork of the statsd protocol which aggregates statistics, such as counters and timers, and ships them over UDP to the dogstatsd-server running as part of the Datadog Agent. Dogstatsd adds support for metric tags, which are used to slice metrics along various dimensions.

You can learn about statsd here:

Typical examples of how this can be used with Logstash include counting HTTP hits by response code, summing the total number of bytes of traffic served, and tracking the 50th and 95th percentile of the processing time of requests.

Example:

source,ruby

output

dogstatsd {
  metric_tags => ["host:%{host","role:foo"]
  count => {
    "http.bytes" => "%bytes"
  }
}

}

Constant Summary collapse

RESERVED_CHARACTERS_REGEX =

Regex stolen from statsd code

/[\:\|\@]/

Instance Method Summary collapse

Instance Method Details

#closeObject



112
113
114
# File 'lib/logstash/outputs/dogstatsd.rb', line 112

def close
  @client.close
end

#receive(event) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/logstash/outputs/dogstatsd.rb', line 78

def receive(event)
  @logger.debug? and @logger.debug("Event: #{event}")

  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

  @decrement.each do |metric|
    @client.decrement(event.sprintf(metric), metric_opts)
  end

  @count.each do |metric, val|
    @client.count(event.sprintf(metric), event.sprintf(val), metric_opts)
  end

  @histogram.each do |metric, val|
    @client.histogram(event.sprintf(metric), event.sprintf(val), metric_opts)
  end

  @set.each do |metric, val|
    @client.set(event.sprintf(metric), event.sprintf(val), metric_opts)
  end

  @gauge.each do |metric, val|
    @client.gauge(event.sprintf(metric), event.sprintf(val), metric_opts)
  end
end

#registerObject



73
74
75
# File 'lib/logstash/outputs/dogstatsd.rb', line 73

def register
  @client = Datadog::Statsd.new(@host, @port)
end