Class: Fluent::ElasticsearchSlowLogParser
- Inherits:
-
Parser
- Object
- Parser
- Fluent::ElasticsearchSlowLogParser
- Defined in:
- lib/fluent/plugin/parser_es_slow_query.rb
Constant Summary collapse
- REGEXP =
/^\[(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3})\]\[(?<severity>[a-zA-Z]+\s*)\]\[(?<source>\S+)\] \[(?<node>\S+)\] \[(?<index>\w+)\]\[(?<shard>\d+)\] took\[(?<took>.+)\], took_millis\[(?<took_millis>\d+)\], types\[(?<types>.*)\], stats\[(?<stats>.*)\], search_type\[(?<search_type>.*)\], total_shards\[(?<total_shards>\d+)\], source\[(?<source_body>.*)\], extra_source\[(?<extra_source>.*)\]/- TIME_FORMAT =
"%Y-%m-%d %H:%M:%S,%N"
Instance Method Summary collapse
-
#initialize ⇒ ElasticsearchSlowLogParser
constructor
A new instance of ElasticsearchSlowLogParser.
- #parse(text) ⇒ Object
- #patterns ⇒ Object
Constructor Details
#initialize ⇒ ElasticsearchSlowLogParser
8 9 10 11 12 |
# File 'lib/fluent/plugin/parser_es_slow_query.rb', line 8 def initialize super @time_parser = TextParser::TimeParser.new(TIME_FORMAT) @mutex = Mutex.new end |
Instance Method Details
#parse(text) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
# File 'lib/fluent/plugin/parser_es_slow_query.rb', line 18 def parse(text) m = REGEXP.match(text) unless m if block_given? yield nil, nil return else return nil, nil end end shard = m['shard'].to_i took_millis = m['took_millis'].to_i total_shards = m['total_shards'].to_i time = m['time'] time = @mutex.synchronize { @time_parser.parse(time) } record = { 'severity' => m['severity'], 'source' => m['source'], 'node' => m['node'], 'index' => m['index'], 'shard' => shard, 'took' => m['took'], 'took_millis' => took_millis, 'types' => m['types'], 'stats' => m['stats'], 'search_type' => m['search_type'], 'total_shards' => total_shards, 'source_body' => m['source_body'], 'extra_source' => m['extra_source'] } record["time"] = m['time'] if @keep_time_key if block_given? yield time, record else return time, record end end |
#patterns ⇒ Object
14 15 16 |
# File 'lib/fluent/plugin/parser_es_slow_query.rb', line 14 def patterns {'format' => REGEXP, 'time_format' => TIME_FORMAT} end |