fluent-plugin-docker-inspect 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3894563a74416e368a027c85681fd347740c4cbc
4
+ data.tar.gz: 4be52cabe8ef9e9e3759a41388df8b2b1b37b4ae
5
+ SHA512:
6
+ metadata.gz: 260cf1c9c0ccbbc2efec16d4fcd1e7221ee4777ce8769fb8d60a96486b0dd38e32d991da6d52a85c7d2e6e12805b679ed5cd79bfecd699248b10d42424fb8599
7
+ data.tar.gz: 4ae571c7de83ef84032df1104eb0fa438f886a3246288b0ddfcc8b16bdfcccb5bed933bb40a04a772a27e0e2db54ac4001c62428d3ad08bde74e956b2dbd020c
@@ -0,0 +1,13 @@
1
+ ~*
2
+ #*
3
+ *~
4
+ [._]*.s[a-w][a-z]
5
+ .DS_Store
6
+
7
+ *.gem
8
+ .bundle
9
+ Gemfile.lock
10
+ vendor
11
+ .ruby-version
12
+
13
+ test/tmp/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
4
+
5
+ gem 'docker-api'
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 WAKAYAMA Shirou
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ Docker inspect plugin for fluentd
2
+ ==========================================
3
+
4
+ Overview
5
+ ----------
6
+
7
+ **docker-inspect** plugin emits docker container inspections. If multiple containers running, emit events by each containers.
8
+
9
+ Installation
10
+ --------------------
11
+
12
+ Simply use RubyGems::
13
+
14
+ gem install fluent-plugin-docker-inspect
15
+
16
+
17
+ Configuration
18
+ ------------------
19
+
20
+ ::
21
+
22
+ <source>
23
+ type docker_inspect
24
+ emit_interval 10
25
+ tag "docker.#{Socket.gethostname}"
26
+ add_addr_tag yes
27
+ </source>
28
+
29
+
30
+ emit_interval
31
+ emit interval by second. (default 60 sec)
32
+ tag
33
+ fluentd tag.
34
+ docker_url
35
+ specify docker_url if remote. ex: ``tcp://example.com:5422``. If docker runs local, no need to specify this param.
36
+ add_addr_tag
37
+ if specify some string such as 'yes', add local host ipv4 addr. (default: nil)
38
+
39
+ License
40
+ ----------
41
+
42
+ MIT
43
+
44
+ Authors
45
+ --------
46
+
47
+ - WAKAYAMA Shirou (shirou.faw@gmail.com)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ require 'rake/clean'
6
+
7
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "fluent-plugin-docker-inspect"
3
+ gem.version = File.read("VERSION").strip
4
+
5
+ gem.authors = ["WAKAYAMA Shirou"]
6
+ gem.email = ["shirou.faw@gmail.com"]
7
+ gem.description = ''
8
+ gem.summary = gem.description
9
+ gem.homepage = "https://github.com/shirou/fluent-plugin-docker-inspect"
10
+ gem.license = 'MIT'
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.require_paths = ["lib"]
15
+ gem.has_rdoc = false
16
+ gem.required_ruby_version = '>= 1.9.2'
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.33"
19
+ gem.add_development_dependency "rake", ">= 0.9.2"
20
+ gem.add_development_dependency "simplecov", ">= 0.5.4"
21
+ gem.add_development_dependency "rr", ">= 1.0.0"
22
+ end
@@ -0,0 +1,113 @@
1
+ module Fluent
2
+ class DockerInspectInput < Input
3
+ Fluent::Plugin.register_input('docker_inspect', self)
4
+
5
+ config_param :emit_interval, :integer, :default => 60
6
+ config_param :docker_url, :string, :default => nil
7
+ config_param :tag, :string, :default => nil
8
+ config_param :add_addr_tag, :string, :default => nil
9
+
10
+ unless method_defined?(:log)
11
+ define_method(:log) { $log }
12
+ end
13
+
14
+ def initialize
15
+ super
16
+ require 'json'
17
+ require 'docker'
18
+ require 'socket'
19
+
20
+ Docker.url = @docker_url if @docker_url
21
+ @host_addr = get_ipaddress
22
+ end
23
+
24
+ class TimerWatcher < Coolio::TimerWatcher
25
+ def initialize(interval, repeat, log, &callback)
26
+ @callback = callback
27
+ # Avoid long shutdown time
28
+ @num_call = 0
29
+ @call_interval = interval / 10
30
+ @log = log
31
+ super(10, repeat)
32
+ end
33
+
34
+ def on_timer
35
+ @num_call += 1
36
+ if @num_call >= @call_interval
37
+ @num_call = 0
38
+ @callback.call
39
+ end
40
+ rescue => e
41
+ @log.error e.to_s
42
+ @log.error_backtrace
43
+ end
44
+ end
45
+
46
+ def configure(conf)
47
+ super
48
+ end
49
+
50
+ def start
51
+ @started_at = Time.now.to_i
52
+
53
+ @loop = Coolio::Loop.new
54
+ @timer = TimerWatcher.new(@emit_interval, true, log, &method(:on_timer))
55
+ @loop.attach(@timer)
56
+ @thread = Thread.new(&method(:run))
57
+
58
+ @es = MultiEventStream.new
59
+ end
60
+
61
+ def shutdown
62
+ log.info "shutdown docker_inspect plugin"
63
+
64
+ @loop.watchers.each {|w| w.detach }
65
+ @loop.stop
66
+ @thread.join
67
+ end
68
+
69
+ def run
70
+ @loop.run
71
+ rescue => e
72
+ log.error "unexpected error", :error=> e.to_s
73
+ log.error_backtrace
74
+ end
75
+
76
+ def on_timer
77
+ time = Engine.now
78
+ tag = @tag
79
+ if @add_addr_tag && @host_addr
80
+ tag = [tag, @host_addr].join(".")
81
+ end
82
+
83
+ get_inspect.each { | i |
84
+ @es.add(time, i)
85
+ }
86
+ router.emit_stream(tag, @es)
87
+ end
88
+
89
+ private
90
+ def get_ipaddress
91
+ Socket.getifaddrs.select{|x|
92
+ if x.addr.ipv4?
93
+ return x.addr.ip_address unless x.addr.ipv4_loopback?
94
+ end
95
+ }
96
+ return nil
97
+ end
98
+
99
+ def get_containers
100
+ Docker::Container.all(:all => true)
101
+ end
102
+
103
+ def get_inspect
104
+ result = []
105
+
106
+ get_containers.each { |c|
107
+ result.push c.json
108
+ }
109
+
110
+ return result
111
+ end
112
+ end
113
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-docker-inspect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - WAKAYAMA Shirou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.33
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.33
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ description: ''
70
+ email:
71
+ - shirou.faw@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.rst
80
+ - Rakefile
81
+ - VERSION
82
+ - fluent-plugin-docker-inspect.gemspec
83
+ - lib/fluent/plugin/in_docker_inspect.rb
84
+ homepage: https://github.com/shirou/fluent-plugin-docker-inspect
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.9.2
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: ''
108
+ test_files: []