Class: LogStash::Outputs::Statsd

Inherits:
Base show all
Defined in:
lib/logstash/outputs/statsd.rb

Overview

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)

Constant Summary collapse

RESERVED_CHARACTERS_REGEX =

Regex stolen from statsd code

/[\:\|\@]/

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#build_stat(metric, sender = @sender) ⇒ Object

def receive



110
111
112
113
114
115
# 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) ⇒ 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
# 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

#registerObject



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

def register
  require "statsd"
  @client = Statsd.new(@host, @port)
end