mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
initial statsd output
This commit is contained in:
parent
4474390491
commit
f8f4c0e46a
4 changed files with 71 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -19,6 +19,7 @@ gem "sass" # License: MIT
|
|||
gem "mongo" # outputs/mongodb, License: Apache 2.0
|
||||
gem "redis" # outputs/redis, License: MIT-style
|
||||
gem "gelf" # outputs/gelf, # License: MIT-style
|
||||
gem "statsd-ruby", "~> 0.3.0" # outputs/statsd, # License: As-Is
|
||||
|
||||
# For testing/dev
|
||||
group :development do
|
||||
|
|
68
lib/logstash/outputs/statsd.rb
Normal file
68
lib/logstash/outputs/statsd.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require "logstash/outputs/base"
|
||||
require "logstash/namespace"
|
||||
|
||||
class LogStash::Outputs::Statsd < LogStash::Outputs::Base
|
||||
# Regex stolen from statsd code
|
||||
RESERVED_CHARACTERS_REGEX = /[\.\:\|\@]/
|
||||
config_name "statsd"
|
||||
|
||||
|
||||
# The address of the Statsd server.
|
||||
config :host, :validate => :string
|
||||
|
||||
# The port to connect to on your statsd server.
|
||||
config :port, :validate => :number, :default => 8125
|
||||
|
||||
# The statsd namespace to use for this metric
|
||||
config :namespace, :validate => :string, :default => "logstash"
|
||||
|
||||
# The name of the sender.
|
||||
# Dots will be replaced with underscores
|
||||
config :sender, :validate => :string, :default => "%{@source_host}"
|
||||
|
||||
# The type of metric to send (count, increment, decrement, timing)
|
||||
config :metric_type, :validate => :string, :default => "increment"
|
||||
|
||||
# The name of the metric. Sent as is to statsd.
|
||||
# Note that graphite uses dots as delimiters
|
||||
config :metric_name, :validate => :string, :default => "%{@source_path}"
|
||||
|
||||
# The sample rate for the metric
|
||||
config :sample_rate, :validate => :number, :default => 1
|
||||
|
||||
# The 'value' for count and timing
|
||||
config :metric_value, :validate => :number, :default => ""
|
||||
|
||||
# The final metric sent to statsd will look like the following (assuming defaults)
|
||||
# logstash.sender.file_name
|
||||
#
|
||||
# Enable debugging output?
|
||||
config :debug, :validate => :boolean, :default => false
|
||||
|
||||
public
|
||||
def register
|
||||
require "statsd"
|
||||
@client = Statsd.new(@host, @port)
|
||||
end # def register
|
||||
|
||||
public
|
||||
def receive(event)
|
||||
@client.namespace = event.sprintf(@namespace)
|
||||
@sender = event.sprintf(@sender)
|
||||
@metric_name = event.sprintf(@metric_name)
|
||||
@sender = @sender.gsub('::','.').gsub(RESERVED_CHARACTERS_REGEX, '_')
|
||||
@metric_name = @metric_name.gsub('::','.').gsub(RESERVED_CHARACTERS_REGEX, '_')
|
||||
@stat = "#{@sender}.#{@metric_name}"
|
||||
@logger.debug(["statsd sending event", { :host => @host, :event => event, :sender => @sender, :stat => @stat, :metric_type => @metric_type }])
|
||||
case @metric_type
|
||||
when "increment"
|
||||
@client.increment(@stat)
|
||||
when "decrement"
|
||||
@client.decrement(@stat)
|
||||
when "count"
|
||||
@client.count(@stat, @metric_value)
|
||||
when "timing"
|
||||
@client.timing(@stat, @metric_value)
|
||||
end
|
||||
end # def receive
|
||||
end # class LogStash::Outputs::Statsd
|
|
@ -43,6 +43,7 @@ class LogStash::Test
|
|||
check_lib("redis", "redis", :optional,
|
||||
"required for stomp input and output"),
|
||||
check_lib("gelf", "gelf", :optional, "required for gelf (graylog2) output"),
|
||||
check_lib("statsd", "statsd-ruby", :optional, "required for statsd output"),
|
||||
|
||||
# logstash web
|
||||
check_lib("mizuno", "mizuno", :required, "needed for logstash web"),
|
||||
|
|
|
@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.add_dependency "mongo" # outputs/mongodb
|
||||
spec.add_dependency "gelf" # outputs/gelf
|
||||
spec.add_dependency "statsd-ruby" # outputs/statsd
|
||||
|
||||
# For the 'grok' filter
|
||||
spec.add_dependency("jls-grok", "~> 0.4.7")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue