Class: Fluent::DockerInspectInput
- Inherits:
-
Input
- Object
- Input
- Fluent::DockerInspectInput
- Defined in:
- lib/fluent/plugin/in_docker_inspect.rb
Defined Under Namespace
Classes: TimerWatcher
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ DockerInspectInput
constructor
A new instance of DockerInspectInput.
- #on_timer ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ DockerInspectInput
29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 29 def initialize super require 'json' require 'docker' require 'socket' Docker.url = @docker_url if @docker_url @host_addr = get_ipaddress end |
Instance Method Details
#configure(conf) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 61 def configure(conf) super # Read configuration for keys and create a hash @keys = Hash.new conf.elements.select { |element| element.name == 'keys' }.each { |element| element.each_pair { |key_name, path| element.has_key?(key_name) # to suppress unread configuration warning @keys[key_name] = path @log.info "Added keys: #{key_name}=>#{@keys[key_name]}" } } end |
#on_timer ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 101 def on_timer time = Engine.now tag = @tag if @add_addr_tag && @host_addr tag = [tag, @host_addr].join(".") end inspect = get_inspect if inspect.length == 0 return end inspect.each { | i | if @keys.length > 0 # keys are specfied k = Hash.new changed = false @keys.each do |key_name, path| tmp = dig(i, path) next if tmp == "" k[key_name] = tmp changed = true # if nothing matched, not sent end if @include_tag k[@include_tag] = tag end @es.add(time, k) if changed else @es.add(time, i) end } router.emit_stream(tag, @es) end |
#run ⇒ Object
94 95 96 97 98 99 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 94 def run @loop.run rescue => e log.error "unexpected error", :error=> e.to_s log.error_backtrace end |
#shutdown ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 86 def shutdown log.info "shutdown docker_inspect plugin" @loop.watchers.each {|w| w.detach } @loop.stop @thread.join end |
#start ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 75 def start @started_at = Time.now.to_i @loop = Coolio::Loop.new @timer = TimerWatcher.new(@emit_interval, true, log, &method(:on_timer)) @loop.attach(@timer) @thread = Thread.new(&method(:run)) @es = MultiEventStream.new end |