Class: Fluent::DockerHostname

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_docker_hostname.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



9
10
11
12
13
14
# File 'lib/fluent/plugin/filter_docker_hostname.rb', line 9

def configure(conf)
  super

  Docker.url = @docker_url
  @containerid_hash = Hash.new
end

#filter_stream(tag, es) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fluent/plugin/filter_docker_hostname.rb', line 30

def filter_stream(tag, es)
  new_es = MultiEventStream.new

  container_id = tag.match(/(\w{64})/)
  @containerid_hash[container_id] ||= get_appname(container_id)

  es.each {|time, record|
    record[:container_hostname] = @containerid_hash[container_id]
    new_es.add(time, record)
  }

  return new_es
end

#get_appname(container_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fluent/plugin/filter_docker_hostname.rb', line 16

def get_appname(container_id)
  Docker::Container.all.each do |obj|
    container_json = obj.json

    if container_id.to_s == container_json['Id'].to_s
      config = container_json['Config']

      return config['Hostname']
    end
  end

  return nil
end