Class: Fluent::SolrOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::SolrOutput
- Includes:
- SetTagKeyMixin, SetTimeKeyMixin
- Defined in:
- lib/fluent/plugin/out_solr.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ SolrOutput
constructor
A new instance of SolrOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ SolrOutput
Returns a new instance of SolrOutput.
13 14 15 16 17 |
# File 'lib/fluent/plugin/out_solr.rb', line 13 def initialize super require 'msgpack' require 'socket' end |
Instance Method Details
#configure(conf) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/fluent/plugin/out_solr.rb', line 19 def configure(conf) super @host = conf.has_key?('host') ? conf['host'] : 'localhost' @port = conf.has_key?('port') ? conf['port'] : '8983' @core = conf.has_key?('core') ? conf['core'] : '' end |
#format(tag, time, record) ⇒ Object
37 38 39 |
# File 'lib/fluent/plugin/out_solr.rb', line 37 def format(tag, time, record) record.to_msgpack end |
#shutdown ⇒ Object
33 34 35 |
# File 'lib/fluent/plugin/out_solr.rb', line 33 def shutdown super end |
#start ⇒ Object
28 29 30 31 |
# File 'lib/fluent/plugin/out_solr.rb', line 28 def start super @connection = Solr::Connection.new('http://'+@host+':'+@port+'/solr/'+@core) end |
#write(chunk) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fluent/plugin/out_solr.rb', line 41 def write(chunk) chunk.msgpack_each { |record| doc = Solr::Document.new( :id => record["tag"] + "_" + Socket::gethostname + "_" + record["core"] + "_" + record["thread"] + "_" + record["timestamp"].gsub(/[\s\.:-]/, ""), :host_s => Socket::gethostname, :timestamp_s => record["timestamp"], :level_s => record["level"], :thread_s => record["thread"], :class_s => record["class"], :core_s => record["core"], :webapp_s => record["webapp"], :path_s => record["path"], :params_s => record["params"], :hits_tl => record["hits"], :status_ti => record["status"], :qtime_tl => record["qtime"], :time_tl => record["time"], :tag_s => record["tag"] ) request = Solr::Request::AddDocument.new(doc) response = @connection.send(request) if response.ok? ={} .update(:softCommit => "true") response = @connection.send(Solr::Request::Commit4.new()) end } end |