Class: Fluent::Plugin::MysqlReplicatorElasticsearchOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::MysqlReplicatorElasticsearchOutput
- Defined in:
- lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb
Constant Summary collapse
- DEFAULT_BUFFER_TYPE =
"memory"
- DEFAULT_TAG_FORMAT =
/(?<index_name>[^\.]+)\.(?<type_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$/
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #formatted_to_msgpack_binary? ⇒ Boolean
-
#initialize ⇒ MysqlReplicatorElasticsearchOutput
constructor
A new instance of MysqlReplicatorElasticsearchOutput.
- #multi_workers_ready? ⇒ Boolean
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ MysqlReplicatorElasticsearchOutput
Returns a new instance of MysqlReplicatorElasticsearchOutput.
25 26 27 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 25 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 29 def configure(conf) super if @tag_format.nil? || @tag_format == DEFAULT_TAG_FORMAT @tag_format = DEFAULT_TAG_FORMAT else @tag_format = Regexp.new(conf['tag_format']) end end |
#format(tag, time, record) ⇒ Object
43 44 45 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 43 def format(tag, time, record) [tag, time, record].to_msgpack end |
#formatted_to_msgpack_binary? ⇒ Boolean
55 56 57 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 55 def formatted_to_msgpack_binary? true end |
#multi_workers_ready? ⇒ Boolean
51 52 53 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 51 def multi_workers_ready? true end |
#shutdown ⇒ Object
47 48 49 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 47 def shutdown super end |
#start ⇒ Object
39 40 41 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 39 def start super end |
#write(chunk) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fluent/plugin/out_mysql_replicator_elasticsearch.rb', line 59 def write(chunk) = [] chunk.msgpack_each do |tag, time, record| tag_parts = tag.match(@tag_format) target_index = tag_parts['index_name'] target_type = tag_parts['type_name'] id_key = tag_parts['primary_key'] if tag_parts['event'] == 'delete' = { "delete" => {"_index" => target_index, "_type" => target_type, "_id" => record[id_key]} } << Yajl::Encoder.encode() else = { "index" => {"_index" => target_index, "_type" => target_type} } if id_key && record[id_key] ['index']['_id'] = record[id_key] end << Yajl::Encoder.encode() << Yajl::Encoder.encode(record) end end << "" http = Net::HTTP.new(@host, @port.to_i) http.use_ssl = @ssl request = Net::HTTP::Post.new('/_bulk', {'content-type' => 'application/json; charset=utf-8'}) if @username && @password request.basic_auth(@username, @password) end request.body = .join("\n") http.request(request).value end |