Skip to content

Instantly share code, notes, and snippets.

@gaiottino
Created December 16, 2010 15:27
Show Gist options
  • Save gaiottino/743519 to your computer and use it in GitHub Desktop.
Save gaiottino/743519 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dripdrop/node'
require 'eventmachine-tail'
Thread.abort_on_exception = true
class Tailer < EventMachine::FileTail
def initialize(zmq_queue, path, startpos = -1)
super(path, startpos)
@zmq_queue = zmq_queue
@buffer = BufferedTokenizer.new
end
def receive_data(data)
@buffer.extract(data).each do |line|
@zmq_queue.send_message(:name => Time.now.to_i.to_s, :body => line)
end
end
end
class Watcher < EventMachine::FileGlobWatch
def initialize(zm_queue, pathglob, interval=5)
super(pathglob, interval)
@zmq_queue = zm_queue
@tailers = {}
end
def file_deleted(path)
tailer = @tailers.delete(path)
tailer.close if tailer
puts "Removed: #{path}"
end
def file_found(path)
@tailers[path] = Tailer.new(@zmq_queue, path)
puts "Found: #{path}"
end
end
DripDrop::Node.new do
route :exposures_pub, :zmq_publish, 'tcp://10.224.82.225:2200', :bind
Watcher.new(exposures_pub, "/mnt/var/log/apache2/rich-access*")
puts "Server started"
end.start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment