fluent-plugin-docker-format 0.1.0

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: b01883397bc25c175beeb51f0dee5eeb0418eb83
4
+ data.tar.gz: b0a4bc332d9c179b789e1392d30d9eee0a21d31c
5
+ SHA512:
6
+ metadata.gz: c235243284c7146c68712b0be4f7f655903fea69113e4594818671c81835b76be9e0e4679b8b7b1a48ec7b93074f333ec706673d1e610aff63c1fa0700814b16
7
+ data.tar.gz: 11915f2fd54669bf12cdab326b891076971bc404fe0abfcaadea1db0a404d22b756dd1c400a6a7d25af780331bec2d34e888df35fd6b15dc52d6c5f4b095b612
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-docker-format.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alex Hornung
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Fluent::Plugin::Docker::Format
2
+
3
+ This fluentd output filter plugin can parse a docker container's config.json associated with a certain log entry and add information from config.json to the record.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fluent-plugin-docker-format'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-docker-format
19
+
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ <match docker.var.lib.docker.containers.*.*.log>
25
+ type docker_format
26
+ docker_containers_path /var/lib/docker/containers
27
+ container_id ${tag_parts[5]}
28
+ tag docker.all
29
+ </match>
30
+ ```
31
+
32
+ The `docker_containers_path` is optional and defaults to `/var/lib/docker/containers`.
33
+
34
+ The `container_id` parameter can either be a string with the id, or use the special interpolated substitution `${tag_parts[<some number>]}`. The tag parts are the dot-separated parts of the incoming tag, so that in the above example they would match the first star.
35
+
36
+ A full example:
37
+
38
+ ```
39
+ <source>
40
+ type tail
41
+ path /var/lib/docker/containers/*/*-json.log
42
+ pos_file /var/log/fluentd-docker.pos
43
+ time_format %Y-%m-%dT%H:%M:%S
44
+ tag docker.*
45
+ format json
46
+ </source>
47
+
48
+ <match docker.var.lib.docker.containers.*.*.log>
49
+ type docker_format
50
+ container_id ${tag_parts[5]}
51
+ tag docker.all
52
+ </match>
53
+ ```
54
+
55
+ The output record will have two additional fields, `container_id` and `container_name`.
56
+
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-docker-format"
7
+ spec.version = File.read("VERSION").strip
8
+ spec.authors = ["Alex Hornung"]
9
+ spec.email = ["alex@alexhornung.com"]
10
+ spec.description = %q{fluentd output filter plugin to parse the docker config.json related to a container log file.}
11
+ spec.summary = spec.description
12
+ spec.homepage = "https://github.com/bwalex/fluent-plugin-docker-format"
13
+ spec.license = "MIT"
14
+ spec.has_rdoc = false
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 10.4.2"
23
+
24
+ spec.add_dependency "fluentd", "~> 0.10.17"
25
+ end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+
3
+ module Fluent
4
+ class DockerFormatOutput < Output
5
+ Fluent::Plugin.register_output('docker_format', self)
6
+ config_param :tag, :string
7
+ config_param :container_id, :string
8
+ config_param :docker_containers_path, :string, :default => '/var/lib/docker/containers'
9
+
10
+ def configure(conf)
11
+ super
12
+ @id_to_name = {}
13
+ end
14
+
15
+ def emit(tag, es, chain)
16
+ es.each do |time,record|
17
+ Engine.emit(@tag, time, format_record(tag, record))
18
+ end
19
+
20
+ chain.next
21
+ end
22
+
23
+ private
24
+
25
+ def interpolate(tag, str)
26
+ tag_parts = tag.split('.')
27
+
28
+ str.gsub(/\$\{tag_parts\[(\d+)\]\}/) { |m| tag_parts[$1.to_i] }
29
+ end
30
+
31
+ def get_name_from_cfg(id)
32
+ begin
33
+ docker_cfg = JSON.parse(File.read("#{@docker_containers_path}/#{id}/config.json"))
34
+ container_name = docker_cfg['Name']
35
+ rescue
36
+ container_name = "<unknown>"
37
+ end
38
+ container_name
39
+ end
40
+
41
+ def get_name(id)
42
+ @id_to_name[id] = get_name_from_cfg(id) unless @id_to_name.has_key? id
43
+ @id_to_name[id]
44
+ end
45
+
46
+ def format_record(tag, record)
47
+ id = interpolate(tag, @container_id)
48
+ record['container_id'] = id
49
+ record['container_name'] = get_name(id)
50
+ record
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-docker-format
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Hornung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 10.4.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 10.4.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluentd
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.17
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.17
55
+ description: fluentd output filter plugin to parse the docker config.json related
56
+ to a container log file.
57
+ email:
58
+ - alex@alexhornung.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - VERSION
69
+ - fluent-plugin-docker-format.gemspec
70
+ - lib/fluent/plugin/out_docker_format.rb
71
+ homepage: https://github.com/bwalex/fluent-plugin-docker-format
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.14
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: fluentd output filter plugin to parse the docker config.json related to a
95
+ container log file.
96
+ test_files: []