mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- use event machine timers
This commit is contained in:
parent
e020e8487e
commit
7f66dcc2ea
1 changed files with 21 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue