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
Returns a new instance of DockerInspectInput.
28 29 30 31 32 33 34 35 36 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 28 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
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 60 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
100 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 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 100 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 @es.add(time, k) if changed else @es.add(time, i) end } router.emit_stream(tag, @es) end |
#run ⇒ Object
93 94 95 96 97 98 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 93 def run @loop.run rescue => e log.error "unexpected error", :error=> e.to_s log.error_backtrace end |
#shutdown ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 85 def shutdown log.info "shutdown docker_inspect plugin" @loop.watchers.each {|w| w.detach } @loop.stop @thread.join end |
#start ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fluent/plugin/in_docker_inspect.rb', line 74 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 |