Class: Groonga::QueryLog::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/query-log/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



26
27
28
29
30
31
# File 'lib/groonga/query-log/parser.rb', line 26

def initialize(options={})
  @options = options
  @slow_operation_threshold = options[:slow_operation_threshold]
  @slow_response_threshold = options[:slow_response_threshold]
  @parsing_statistics = {}
end

Instance Method Details

#parse(input) {|statistics| ... } ⇒ Object

Parses query-log file as stream to Analyzer::Statistics including some informations for each query.

Parameters:

  • input (IO)

    IO for input query log file.

Yields:

  • (statistics)

    if a block is specified, it is called every time a query is finished parsing.

Yield Parameters:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/groonga/query-log/parser.rb', line 42

def parse(input, &block)
  input.each_line do |line|
    next unless line.valid_encoding?
    case line
    when /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\.(\d+)\|(.+?)\|([>:<])/
      year, month, day, hour, minutes, seconds, micro_seconds =
        $1, $2, $3, $4, $5, $6, $7
      context_id = $8
      type = $9
      rest = $POSTMATCH.strip
      time_stamp = Time.local(year, month, day, hour, minutes, seconds,
                              micro_seconds)
      parse_line(time_stamp, context_id, type, rest, &block)
    end
  end
end

#parsing_statisticsObject



59
60
61
# File 'lib/groonga/query-log/parser.rb', line 59

def parsing_statistics
  @parsing_statistics.values
end