Class: OAS::LogCollector::Manager
- Inherits:
-
Object
- Object
- OAS::LogCollector::Manager
- Defined in:
- lib/oas/log_collector/manager.rb
Instance Method Summary collapse
- #collect(source) ⇒ Object
- #get_last_run(hostname) ⇒ Object
-
#initialize(opts = {}) ⇒ Manager
constructor
A new instance of Manager.
- #options ⇒ Object
- #set_last_run(hostname, timestamp) ⇒ Object
- #start! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Manager
Returns a new instance of Manager.
9 10 11 12 13 14 |
# File 'lib/oas/log_collector/manager.rb', line 9 def initialize(opts = {}) sources = opts.delete(:sources) || [] sources.each { |host, user, port| (opts[:sources] ||= []) << OAS::LogCollector::Source.new(host, user, port || 22) } .merge!(opts) end |
Instance Method Details
#collect(source) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/oas/log_collector/manager.rb', line 34 def collect(source) hostname = source.host result = source.find([:source_logs_path], { :mtime => "-#{[:days_to_search]}", :type => 'f', :regex => '.*\.log\.[0-9]+\.bz2' }) files = Hash.new total = 0 = last_run = get_last_run(hostname) result.sort!.each do |path| log_file = OAS::LogCollector::LogFile.new(path) if log_file. > Integer(last_run) && total < [:files_to_copy] files[path] = File.join([:logs_path], hostname, log_file.year, log_file.month, log_file.day, log_file.name) = log_file. total += 1 end end if files.any? source.download(files) set_last_run(hostname, ) end end |
#get_last_run(hostname) ⇒ Object
61 62 63 64 65 |
# File 'lib/oas/log_collector/manager.rb', line 61 def get_last_run(hostname) OAS::LogCollector.redis do |conn| conn.hget("timestamps", hostname) || 0 end end |
#options ⇒ Object
30 31 32 |
# File 'lib/oas/log_collector/manager.rb', line 30 def OAS::LogCollector. end |
#set_last_run(hostname, timestamp) ⇒ Object
67 68 69 70 71 |
# File 'lib/oas/log_collector/manager.rb', line 67 def set_last_run(hostname, ) OAS::LogCollector.redis do |conn| conn.hset("timestamps", hostname, ) end end |
#start! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/oas/log_collector/manager.rb', line 16 def start! loop do threads = [] [:sources].each do |source| threads << Thread.new do collect(source) end end threads.each(&:join) sleep [:sleep_seconds] end end |