Class: Fluent::DockerEventStreamInput
- Inherits:
-
Input
- Object
- Input
- Fluent::DockerEventStreamInput
- Defined in:
- lib/fluent/plugin/in_docker_events.rb,
lib/fluent/plugin/in_docker_event_streams.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(r) ⇒ Object
-
#initialize ⇒ DockerEventStreamInput
constructor
A new instance of DockerEventStreamInput.
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ DockerEventStreamInput
Returns a new instance of DockerEventStreamInput.
13 14 15 16 |
# File 'lib/fluent/plugin/in_docker_events.rb', line 13 def initialize super require 'docker' end |
Instance Method Details
#configure(conf) ⇒ Object
18 19 20 21 |
# File 'lib/fluent/plugin/in_docker_events.rb', line 18 def configure(conf) super @events = @events.split(',').map {|event| event.strip } end |
#emit(r) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fluent/plugin/in_docker_events.rb', line 45 def emit(r) record = { "id" => r.id, "action" => r.action, "status" => r.status, "type" => r.type, } _container = Thread.new{ results = Docker::Container.get(r.id) }.value if _container record["container"] = { "state" => _container.info["State"], "name" => _container.info["Name"].gsub(/^\//, ''), } _image = Thread.new{ results = Docker::Image.get(_container.info["Image"]) }.value if _image record["container"]["image"] = _image.info["RepoTags"] end end router.emit(@tag, Time.now.to_i, record) end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/fluent/plugin/in_docker_events.rb', line 35 def run while @running Docker::Event.stream do |event| if @events.include?(event.action) emit(event) end end end end |
#shutdown ⇒ Object
30 31 32 33 |
# File 'lib/fluent/plugin/in_docker_events.rb', line 30 def shutdown @running = false @thread.join end |
#start ⇒ Object
23 24 25 26 27 28 |
# File 'lib/fluent/plugin/in_docker_events.rb', line 23 def start super @running = true @thread = Thread.new(&method(:run)) end |