Class: Fluent::DockerTagResolverOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::DockerTagResolverOutput
- Defined in:
- lib/fluent/plugin/out_docker_tag_resolver.rb
Instance Method Summary collapse
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ DockerTagResolverOutput
constructor
A new instance of DockerTagResolverOutput.
- #rewrite_tag(tag, record) ⇒ Object
Constructor Details
#initialize ⇒ DockerTagResolverOutput
Returns a new instance of DockerTagResolverOutput.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fluent/plugin/out_docker_tag_resolver.rb', line 10 def initialize super require 'docker' @containers = Docker::Container.all @find_containers = Proc.new do |id| container = @containers.select{|c| c.id == id}.first if container.nil? @containers = Docker::Container.all @containers.select{|c| c.id == id}.first else container end end end |
Instance Method Details
#emit(tag, es, chain) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/fluent/plugin/out_docker_tag_resolver.rb', line 28 def emit(tag, es, chain) es.each do |time,record| rewrited_tag = rewrite_tag(tag, record) next if rewrited_tag.nil? || tag == rewrited_tag Fluent::Engine.emit(rewrited_tag, time, record) end chain.next end |
#rewrite_tag(tag, record) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fluent/plugin/out_docker_tag_resolver.rb', line 38 def rewrite_tag(tag, record) container_id, _ , _ = tag.split('.').last(3) container = @find_containers.call(container_id) return tag unless container image_name = container.info['Image'] container_name = container.info['Names'].first return tag if image_name.nil? or container_name.nil? container_name.sub!(/^\//, '') container_name.tr!('.','_') image_name.tr!('.','_') rewrited_tag = "docker.container.%s.%s.%s" % [image_name, container_name, container_id] return rewrited_tag end |