mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
adding experimental riemann output
This commit is contained in:
parent
493e7ec708
commit
ddcdf0a063
3 changed files with 106 additions and 1 deletions
2
Gemfile
2
Gemfile
|
@ -32,6 +32,8 @@ gem "gelfd", "0.2.0" #inputs/gelf, # License: Apache 2.0
|
|||
gem "ffi-rzmq", "0.9.0"
|
||||
gem "ffi"
|
||||
|
||||
gem "riemann-client", "0.0.6" #outputs/riemann, License: MIT
|
||||
|
||||
# ruby-debug is broken in 1.9.x due, at a minimum, the following:
|
||||
# Installing rbx-require-relative (0.0.5)
|
||||
# Gem::InstallError: rbx-require-relative requires Ruby version ~> 1.8.7.
|
||||
|
|
103
lib/logstash/outputs/riemann.rb
Normal file
103
lib/logstash/outputs/riemann.rb
Normal file
|
@ -0,0 +1,103 @@
|
|||
require "logstash/outputs/base"
|
||||
require "logstash/namespace"
|
||||
|
||||
# Riemann is a network event stream processing system.
|
||||
#
|
||||
# While Riemann is very similar conceptually to Logstash, it has
|
||||
# much more in terms of being a monitoring system replacement.
|
||||
#
|
||||
# Riemann is used in Logstash much like statsd or other metric-related
|
||||
# outputs
|
||||
#
|
||||
# You can learn about Riemann here:
|
||||
#
|
||||
# * <http://aphyr.github.com/riemann/>
|
||||
# You can see the author talk about it here:
|
||||
# * <http://vimeo.com/38377415>
|
||||
#
|
||||
class LogStash::Outputs::Riemann < LogStash::Outputs::Base
|
||||
config_name "riemann"
|
||||
plugin_status "experimental"
|
||||
|
||||
# The address of the Riemann server.
|
||||
config :host, :validate => :string, :default => "localhost"
|
||||
|
||||
# The port to connect to on your Riemann server.
|
||||
config :port, :validate => :number, :default => 5555
|
||||
|
||||
# The protocol to use
|
||||
# UDP is non-blocking
|
||||
# TCP is blocking
|
||||
#
|
||||
# Logstash's default output behaviour
|
||||
# is to never lose events
|
||||
# As such, we use tcp as default here
|
||||
config :protocol, :validate => ["tcp", "udp"], :default => "tcp"
|
||||
|
||||
# The name of the sender.
|
||||
# This sets the `host` value
|
||||
# in the Riemann event
|
||||
config :sender, :validate => :string, :default => "%{@source_host}"
|
||||
|
||||
# Hash to set Riemann fields
|
||||
# Values are passed through event.sprintf
|
||||
# so macros are usable here
|
||||
#
|
||||
# See Events here:
|
||||
# <http://aphyr.github.com/riemann/concepts.html>
|
||||
#
|
||||
# The following keys are supported:
|
||||
# description, state, metric, ttl, service
|
||||
#
|
||||
# i.e
|
||||
# riemann_event => ["state", "up", "ttl" => "600", "metric" => %{bytes}]
|
||||
# Description, by default, will be set to the event message
|
||||
# but can be overridden here
|
||||
config :riemann_event, :validate => :hash
|
||||
|
||||
#
|
||||
# Enable debugging output?
|
||||
config :debug, :validate => :boolean, :default => false
|
||||
|
||||
public
|
||||
def register
|
||||
require 'riemann/client'
|
||||
@client = Riemann::Client.new(:host => @host, :port => @port)
|
||||
end # def register
|
||||
|
||||
public
|
||||
def receive(event)
|
||||
return unless output?(event)
|
||||
|
||||
# Let's build us an event, shall we?
|
||||
r_event = Hash.new
|
||||
r_event[:host] = event.sprintf(@sender)
|
||||
# riemann doesn't handle floats so we reduce the precision here
|
||||
r_event[:time] = event.unix_timestamp.to_i
|
||||
r_event[:description] = event.message
|
||||
if @riemann_event
|
||||
@riemann_event.each do |key, val|
|
||||
# Catch invalid options since hash syntax doesn't support it
|
||||
unless ["description","state","metric","ttl", "service"].include?(key)
|
||||
@logger.warn("Invalid key specified in riemann_event", :key => key)
|
||||
next
|
||||
end
|
||||
if ["ttl","metric"].include?(key)
|
||||
val = val.to_f if ["ttl","metric"].include?(key)
|
||||
r_event[key.to_sym] = val
|
||||
else
|
||||
r_event[key.to_sym] = event.sprintf(val)
|
||||
end
|
||||
end
|
||||
end
|
||||
r_event[:tags] = @tags if @tags
|
||||
@logger.debug("Riemann event: ", :riemann_event => r_event)
|
||||
begin
|
||||
proto_client = @client.instance_variable_get("@#{@protocol}")
|
||||
@logger.debug("Riemann client proto: #{proto_client.to_s}")
|
||||
proto_client << r_event
|
||||
rescue Exception => e
|
||||
@logger.debug("Unhandled exception", :error => e)
|
||||
end
|
||||
end # def receive
|
||||
end # class LogStash::Outputs::Riemann
|
|
@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
|
|||
spec.add_dependency "mongo" # outputs/mongodb, License: Apache 2.0
|
||||
spec.add_dependency "rack" # License: MIT
|
||||
spec.add_dependency "redis" # outputs/redis, License: MIT-style
|
||||
spec.add_dependency "riemann-client", "~> 0.0.6" # outputs/riemann, License: MIT
|
||||
spec.add_dependency "sass" # License: MIT
|
||||
spec.add_dependency "sinatra" # License: MIT-style
|
||||
spec.add_dependency "statsd-ruby", "~> 0.3.0" # outputs/statsd, # License: As-Is
|
||||
|
@ -60,4 +61,3 @@ Gem::Specification.new do |spec|
|
|||
spec.email = ["jls@semicomplete.com", "petef@databits.net"]
|
||||
spec.homepage = "http://logstash.net/"
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue