- use event machine timers

This commit is contained in:
Jordan Sissel 2010-04-11 15:51:36 +00:00
parent e020e8487e
commit 7f66dcc2ea

View file

@ -17,26 +17,22 @@ module LogStash; module Net; module Clients
end # def initialize
def log_watcher
loop do
@logger.debug "Starting log_watcher loop"
@config.sources.each do |file, logtype|
next if @log_threads.member?(file)
@logger.debug "Starting log_watcher loop"
@config.sources.each do |file, logtype|
next if @log_threads.member?(file)
Dir.glob(file).each do |path|
next if @log_threads.member?(path)
next if File.directory?(path)
@log_threads[path] = Thread.new do
@logger.info "Watching #{path} (type #{logtype})"
File::Tail::Since.new(path).tail do |line|
index(logtype, line.chomp)
end
raise "File::Tail::Since croaked for #{file}!"
end # Thread
end # Dir.glob
end # @config.sources.each
sleep 60 # only check for new logs every minute
end # loop
Dir.glob(file).each do |path|
next if @log_threads.member?(path)
next if File.directory?(path)
@log_threads[path] = Thread.new do
@logger.info "Watching #{path} (type #{logtype})"
File::Tail::Since.new(path).tail do |line|
index(logtype, line.chomp)
end
raise "File::Tail::Since croaked for #{file}!"
end # Thread
end # Dir.glob
end # @config.sources.each
end # def start_log_watcher
def index(type, string)
@ -57,8 +53,11 @@ module LogStash; module Net; module Clients
end # def IndexEventResponseHandler
def run
Thread.new { log_watcher }
EM.add_periodic_timer(60) do
check_for_logs_to_watch
end
super
end
end
end # def run
end # class LogStash::Net::Clients::Agent
end; end; end # LogStash::Net::Clients