Created
February 20, 2017 02:58
-
-
Save amscotti/a44b8e7d1da88711879d1c57b68da7b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
generator { | |
lines => [ | |
"2017-02-12 14:50:98 DEBUG Main:12 - Test log file", | |
"2017-02-12 14:51:98 INFO Main:13 - Test log file", | |
"2017-02-12 14:52:98 WARN Main:14 - Test log file", | |
"2017-02-12 14:53:98 ERROR Main:15 - Test log file", | |
"2017-02-12 14:54:98 FATAL Main:16 - Test log file" | |
] | |
add_field => { "service" => "a" } | |
add_field => { "environment" => "development" } | |
count => 50 | |
} | |
generator { | |
lines => [ | |
"2017-02-12 14:50:98 DEBUG Main:12 - Test log file", | |
"2017-02-12 14:51:98 INFO Main:13 - Test log file", | |
"2017-02-12 14:52:98 WARN Main:14 - Test log file", | |
"2017-02-12 14:53:98 ERROR Main:15 - Test log file", | |
"2017-02-12 14:54:98 FATAL Main:16 - Test log file" | |
] | |
add_field => { "service" => "b" } | |
add_field => { "environment" => "development" } | |
count => 50 | |
} | |
generator { | |
lines => [ | |
"2017-02-12 14:50:98 DEBUG Main:12 - Test log file", | |
"2017-02-12 14:51:98 INFO Main:13 - Test log file", | |
"2017-02-12 14:52:98 WARN Main:14 - Test log file", | |
"2017-02-12 14:53:98 ERROR Main:15 - Test log file", | |
"2017-02-12 14:54:98 FATAL Main:16 - Test log file" | |
] | |
add_field => { "service" => "a" } | |
add_field => { "environment" => "production" } | |
count => 50 | |
} | |
} | |
output { | |
stdout { codec => rubydebug } | |
rabbitmq { | |
exchange => "logs" | |
host => "localhost" | |
exchange_type => "topic" | |
key => "logs.%{environment}.%{service}" | |
durable => false | |
persistent => false | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bunny' | |
require 'json' | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: read.rb [options]" | |
opts.on('-e', '--environment NAME', 'Environment name') { |v| options[:environment] = v } | |
opts.on('-s', '--service HOST', 'Service name') { |v| options[:service] = v } | |
end.parse! | |
conn = Bunny.new | |
conn.start | |
ch = conn.create_channel | |
x = ch.topic("logs") | |
q = ch.queue("", :exclusive => true) | |
environment = options[:environment] ? options[:environment] : '*' | |
service = options[:service] ? options[:service] : '*' | |
routing_key = "logs.#{environment}.#{service}" | |
q.bind(x, :routing_key => routing_key) | |
puts "Looking for logs matching '#{routing_key}', To exit press CTRL+C" | |
begin | |
q.subscribe(:block => true) do |delivery_info, properties, body| | |
puts "[#{delivery_info.routing_key}] #{JSON.parse(body)["message"]}" | |
end | |
rescue Interrupt => _ | |
ch.close | |
conn.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment