Class: Dexter::Processor

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/dexter/processor.rb

Instance Method Summary collapse

Methods included from Logging

#abort, #log

Constructor Details

#initialize(logfile, options) ⇒ Processor

Returns a new instance of Processor.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dexter/processor.rb', line 5

def initialize(logfile, options)
  @logfile = logfile

  @collector = Collector.new(min_time: options[:min_time], min_calls: options[:min_calls])
  @indexer = Indexer.new(options)

  @log_parser =
    if @logfile == :pg_stat_activity
      PgStatActivityParser.new(@indexer, @collector)
    elsif options[:input_format] == "csv"
      CsvLogParser.new(logfile, @collector)
    elsif options[:input_format] == "sql"
      SqlLogParser.new(logfile, @collector)
    else
      LogParser.new(logfile, @collector)
    end

  @starting_interval = 3
  @interval = options[:interval]

  @mutex = Mutex.new
  @last_checked_at = {}

  log "Started"
end

Instance Method Details

#performObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dexter/processor.rb', line 31

def perform
  if [STDIN, :pg_stat_activity].include?(@logfile)
    Thread.abort_on_exception = true
    Thread.new do
      sleep(@starting_interval)
      loop do
        begin
          process_queries
        rescue PG::ServerError => e
          log "ERROR: #{e.class.name}: #{e.message}"
        end
        sleep(@interval)
      end
    end
  end

  begin
    @log_parser.perform
  rescue Errno::ENOENT => e
    abort "ERROR: #{e.message}"
  end

  process_queries
end