class Fluent::DockerEventStreamInput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_docker_event_streams.rb, line 13
def initialize
  super
  require 'docker'
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_docker_event_streams.rb, line 18
def configure(conf)
  super
  @events = @events.split(',').map {|event| event.strip }
end
emit(r) click to toggle source
# File lib/fluent/plugin/in_docker_event_streams.rb, line 45
def emit(r)
    record = {
        "id" => r.id,
        "action" => r.action,
        "status" => r.status,
        "type" => r.type,
    }
    _container = Docker::Container.get(r.id)
    if _container
        record["container"] = {
            "state" => _container.info["State"],
            "name" => _container.info["Name"].gsub(/^\//, ''),
        }
        _image = Docker::Image.get(_container.info["Image"])
        if _image
            record["container"]["image"] = _image.info["RepoTags"]
        end
    end
    router.emit(@tag, Time.now.to_i, record)
end
run() click to toggle source
# File lib/fluent/plugin/in_docker_event_streams.rb, line 35
def run     
    while @running
        Docker::Event.stream do |event|
            if @events.include?(event.action)
                emit(event)
            end
        end
    end
end
shutdown() click to toggle source
# File lib/fluent/plugin/in_docker_event_streams.rb, line 30
def shutdown
  @running = false
  @thread.join
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_docker_event_streams.rb, line 23
def start
  super

  @running = true
  @thread = Thread.new(&method(:run))
end