fluent-plugin-docker-inspect 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e464b4b66f5ea18153ea874c33f13efbacf886dc
4
- data.tar.gz: db245ffbef8137ad09f37e3e88f6d5abec9a829d
3
+ metadata.gz: 594dfb450c0523dea0239c2e45a266990805f166
4
+ data.tar.gz: a8c25679540b4d60b73524b0340dc2b7a0da4d24
5
5
  SHA512:
6
- metadata.gz: 92ad1084a84924eb3f43d81df0edba9bc6e06347543d8338db1b5edff31366c150dcdb8be25c6284419322ed36ab42892f1c3b71c6625cf560a7fc98ef388bfe
7
- data.tar.gz: aec437c71155986107008bc2fb105dc68e9ddd7303f13b25f7eca8326321cad1b3881d2356250c8b270d8e74033b47071be82cbc5533eb55df8ea4b34147b0b8
6
+ metadata.gz: 3b8f897f41694ad4a0aef7a89871a7de736587bcf398b37a7cc812ecbf2d806d3d8f1af01f6666d67e560f9a40d4776ac05d49441c86f90b8816a14001fc5e95
7
+ data.tar.gz: 77578301ea7b698b62fdf39f667b77684ba055856707247dbd852fb0727bf4f48dc7bb19dec97c9f765da726b07c3c49c355d53cdf03551d1eb3b38f5a537e46
data/README.rst CHANGED
@@ -19,24 +19,38 @@ Configuration
19
19
 
20
20
  ::
21
21
 
22
- <source>
23
- type docker_inspect
24
- emit_interval 10
25
- tag docker
26
- add_addr_tag yes
27
- </source>
28
-
22
+ <source>
23
+ type docker_inspect
24
+ emit_interval 30
25
+ tag docker.inspects
26
+ add_addr_tag yes
27
+ filter { "status": ["running"] } # see Docker remote API
28
+ only_changed true
29
+ <keys>
30
+ id Id
31
+ created Created
32
+ path Path
33
+ status State.Status
34
+ ports NetworkSettings.Ports
35
+ ip_addr NetworkSettings.IPAddress
36
+ mac_addr NetworkSettings.MacAddress
37
+ </keys>
38
+ </source>
29
39
 
30
40
  emit_interval
31
- emit interval by second. (default 60 sec)
41
+ Emit interval by second. (default 60 sec)
32
42
  tag
33
43
  fluentd tag.
34
44
  docker_url
35
- specify docker_url if remote. ex: ``tcp://example.com:5422``. If docker runs local, no need to specify this param.
45
+ Specify docker_url if remote. ex: ``tcp://example.com:5422``. If docker runs local, no need to specify this param.
36
46
  add_addr_tag
37
- if specify some string such as 'yes', add local host ipv4 addr. (default: nil)
47
+ If specify some string such as 'yes', add local host ipv4 addr. (default: nil).
48
+ filter
49
+ Set fileter about container. See Docker remote API to specify params.
38
50
  only_changed
39
- if yes, only emit when docker inspect is changed.
51
+ If true, only emit when docker inspect is changed. (default is true)
52
+ keys
53
+ If set, output values containes only specified keys and path(period separated value). Default is output all values as one JSON.
40
54
 
41
55
  License
42
56
  ----------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,3 +1,15 @@
1
+ # convert dot-string to value in hash
2
+ # ex: NetworkSettings.Ports -> hash[NetworkSettings][Ports]
3
+ def dig(hash, dotted_path)
4
+ parts = dotted_path.split '.', 2
5
+ match = hash[parts[0]]
6
+ if !parts[1] or match.nil?
7
+ return match
8
+ else
9
+ return dig(match, parts[1])
10
+ end
11
+ end
12
+
1
13
  module Fluent
2
14
  class DockerInspectInput < Input
3
15
  Fluent::Plugin.register_input('docker_inspect', self)
@@ -7,7 +19,7 @@ module Fluent
7
19
  config_param :tag, :string, :default => nil
8
20
  config_param :add_addr_tag, :string, :default => nil
9
21
  config_param :filter, :string, :default => nil
10
- config_param :only_changed, :string, :default => nil
22
+ config_param :only_changed, :bool, :default => true
11
23
 
12
24
  unless method_defined?(:log)
13
25
  define_method(:log) { $log }
@@ -47,6 +59,16 @@ module Fluent
47
59
 
48
60
  def configure(conf)
49
61
  super
62
+
63
+ # Read configuration for keys and create a hash
64
+ @keys = Hash.new
65
+ conf.elements.select { |element| element.name == 'keys' }.each { |element|
66
+ element.each_pair { |key_name, path|
67
+ element.has_key?(key_name) # to suppress unread configuration warning
68
+ @keys[key_name] = path
69
+ @log.info "Added keys: #{key_name}=>#{@keys[key_name]}"
70
+ }
71
+ }
50
72
  end
51
73
 
52
74
  def start
@@ -87,7 +109,19 @@ module Fluent
87
109
  return
88
110
  end
89
111
  inspect.each { | i |
90
- @es.add(time, i)
112
+ if @keys.length > 0 # keys are specfied
113
+ k = Hash.new
114
+ changed = false
115
+ @keys.each do |key_name, path|
116
+ tmp = dig(i, path)
117
+ next if tmp == ""
118
+ k[key_name] = tmp
119
+ changed = true # if nothing matched, not sent
120
+ end
121
+ @es.add(time, k) if changed
122
+ else
123
+ @es.add(time, i)
124
+ end
91
125
  }
92
126
  router.emit_stream(tag, @es)
93
127
  end
@@ -121,6 +155,7 @@ module Fluent
121
155
  get_containers.each { |c|
122
156
  result.push c.json
123
157
  }
158
+ # check changed before or not
124
159
  if @only_changed && @last_inspect.to_s == result.to_s
125
160
  return []
126
161
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-docker-inspect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - WAKAYAMA Shirou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd