Class: Logcli::Actions::Elasticsearch
- Inherits:
-
Object
- Object
- Logcli::Actions::Elasticsearch
- Defined in:
- lib/logcli/actions/elasticsearch.rb
Constant Summary collapse
- BULK_SIZE =
100- INDEX_NAME =
'log-index'.freeze
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#elasticsearch_url ⇒ Object
readonly
Returns the value of attribute elasticsearch_url.
-
#filenames ⇒ Object
readonly
Returns the value of attribute filenames.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#mapping_file ⇒ Object
readonly
Returns the value of attribute mapping_file.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(opts) ⇒ Elasticsearch
constructor
A new instance of Elasticsearch.
Constructor Details
#initialize(opts) ⇒ Elasticsearch
Returns a new instance of Elasticsearch.
11 12 13 14 15 16 17 18 |
# File 'lib/logcli/actions/elasticsearch.rb', line 11 def initialize opts @filenames = opts.fetch(:filenames) @mapping_file = opts.fetch(:mapping_file) @elasticsearch_url = opts.fetch(:elasticsearch_url) @buffer = [] @id = 1 @total_records = 0 end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
7 8 9 |
# File 'lib/logcli/actions/elasticsearch.rb', line 7 def buffer @buffer end |
#elasticsearch_url ⇒ Object (readonly)
Returns the value of attribute elasticsearch_url.
7 8 9 |
# File 'lib/logcli/actions/elasticsearch.rb', line 7 def elasticsearch_url @elasticsearch_url end |
#filenames ⇒ Object (readonly)
Returns the value of attribute filenames.
7 8 9 |
# File 'lib/logcli/actions/elasticsearch.rb', line 7 def filenames @filenames end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/logcli/actions/elasticsearch.rb', line 7 def id @id end |
#mapping_file ⇒ Object (readonly)
Returns the value of attribute mapping_file.
7 8 9 |
# File 'lib/logcli/actions/elasticsearch.rb', line 7 def mapping_file @mapping_file end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records.
7 8 9 |
# File 'lib/logcli/actions/elasticsearch.rb', line 7 def total_records @total_records end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/logcli/actions/elasticsearch.rb', line 20 def call create_mapping if mapping_file filenames.each do |filename| File.open(filename).each do |line| @buffer << line if @buffer.count > BULK_SIZE flush end end end if @buffer.count > 0 flush end end |