class LogStash::Outputs::Statsd
statsd is a server for aggregating counters and other metrics to ship to graphite.
The most basic coverage of this plugin is that the 'namespace', 'sender', and 'metric' names are combined into the full metric path like so:
namespace.sender.metric
The general idea is that you send statsd count or latency data and every few seconds it will emit the aggregated values to graphite (aggregates like average, max, stddev, etc)
You can learn about statsd here:
A simple example usage of this is to count HTTP hits by response code; to learn more about that, check out the [log metrics tutorial](../tutorials/metrics-from-logs)
Constants
- RESERVED_CHARACTERS_REGEX
Regex stolen from statsd code
Public Instance Methods
build_stat(metric, sender=@sender)
click to toggle source
# File lib/logstash/outputs/statsd.rb, line 110 def build_stat(metric, sender=@sender) sender = sender.gsub('::','.').gsub(RESERVED_CHARACTERS_REGEX, '_').gsub(".", "_") metric = metric.gsub('::','.').gsub(RESERVED_CHARACTERS_REGEX, '_') @logger.debug? and @logger.debug("Formatted value", :sender => sender, :metric => metric) return "#{sender}.#{metric}" end
receive(event)
click to toggle source
# File lib/logstash/outputs/statsd.rb, line 78 def receive(event) return unless output?(event) @client.namespace = event.sprintf(@namespace) if not @namespace.empty? @logger.debug? and @logger.debug("Original sender: #{@sender}") sender = event.sprintf(@sender) @logger.debug? and @logger.debug("Munged sender: #{sender}") @logger.debug? and @logger.debug("Event: #{event}") @increment.each do |metric| @client.increment(build_stat(event.sprintf(metric), sender), @sample_rate) end @decrement.each do |metric| @client.decrement(build_stat(event.sprintf(metric), sender), @sample_rate) end @count.each do |metric, val| @client.count(build_stat(event.sprintf(metric), sender), event.sprintf(val).to_f, @sample_rate) end @timing.each do |metric, val| @client.timing(build_stat(event.sprintf(metric), sender), event.sprintf(val).to_f, @sample_rate) end @set.each do |metric, val| @client.set(build_stat(event.sprintf(metric), sender), event.sprintf(val), @sample_rate) end @gauge.each do |metric, val| @client.gauge(build_stat(event.sprintf(metric), sender), event.sprintf(val).to_f, @sample_rate) end end
register()
click to toggle source
# File lib/logstash/outputs/statsd.rb, line 72 def register require "statsd" @client = Statsd.new(@host, @port) end