fluent-plugin-chef-api 0.5.1 → 1.0.0

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
- SHA1:
3
- metadata.gz: f0ec63562f649c34c1192372ba89e946190dd94d
4
- data.tar.gz: 1791e941960d83e262b538ef9a5b1db4cff9506a
2
+ SHA256:
3
+ metadata.gz: 070b7dc276e40de20ceabc4847664ee951932c6e23efdddc65c4a010605d30c6
4
+ data.tar.gz: 9bbf0481aef9a47ef2c16bf07cacdbd4220bf0822994f4ca780162b9ffc4103f
5
5
  SHA512:
6
- metadata.gz: 78b43e19595dd67509942094d1e52af0c39815c25d979921968748f5722014154b085592fd25266dcd99884a706f76400ebb7fff8e77023ce7a8319f768838f8
7
- data.tar.gz: e88d95406f913a9f4541fa4f31468fcb071a7beda38f4cd92c250641ed95b4a5f67bd74dd1b9134ad801de3529463fbd2e5828350cb79f7e46a1836c34cd6dad
6
+ metadata.gz: f97e4e02d5923acd6a6ad71d3345577205ebb6453db5240804c4a64f43e43bb5fdf01132b5caefaf711bdd8ee5a24dc754453870fa309d677a25663d5b3ab58f
7
+ data.tar.gz: b312778e66980c087a855aaa26ea93a388d9161ae8d424fbf5ce19df4271e3e6f050836485bcd7eb1f1dd125734f8e9e5c6077e22258c5040c2c953cf05662f1
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-chef-api"
7
- spec.version = "0.5.1"
7
+ spec.version = "1.0.0"
8
8
  spec.authors = ["Yamashita Yuu"]
9
9
  spec.email = ["peek824545201@gmail.com"]
10
10
  spec.license = "Apache-2.0"
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.9"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "fluentd"
23
+ spec.add_dependency "fluentd", ">= 1.0.0"
24
24
  spec.add_dependency "chef-api", "~> 0.5.0"
25
25
  end
@@ -1,9 +1,12 @@
1
- #!/usr/bin/env ruby
1
+ require 'fluent/plugin/input'
2
+ require "chef-api"
2
3
 
3
- module Fluent
4
- class ChefAPIInput < Input
4
+ module Fluent::Plugin
5
+ class ChefAPIInput < Fluent::Plugin::Input
5
6
  Plugin.register_input("chef_api", self)
6
7
 
8
+ helpers :thread
9
+
7
10
  config_param :check_interval, :integer, :default => 60
8
11
  config_param :chef_server_url, :string, :default => nil
9
12
  config_param :client_key, :string, :default => nil
@@ -16,33 +19,32 @@ module Fluent
16
19
 
17
20
  def initialize
18
21
  super
19
- require "chef-api"
20
22
  end
21
23
 
22
24
  class ChefConfig
23
25
  def self.load_file(file)
24
- new(file).instance_eval { @config.dup }
26
+ new(file).instance_eval { @chef_config.dup }
25
27
  end
26
28
 
27
29
  def initialize(file)
28
- @config = {}
30
+ @chef_config = {}
29
31
  instance_eval(::File.read(file))
30
32
  end
31
33
 
32
34
  def chef_server_url(value)
33
- @config[:endpoint] = value
35
+ @chef_config[:endpoint] = value
34
36
  end
35
37
 
36
38
  def node_name(value)
37
- @config[:client] = value
39
+ @chef_config[:client] = value
38
40
  end
39
41
 
40
42
  def client_key(value)
41
- @config[:key] = ::File.read(value)
43
+ @chef_config[:key] = ::File.read(value)
42
44
  end
43
45
 
44
46
  def ssl_verify_mode(value)
45
- @config[:ssl_verify] = value != :verify_none
47
+ @chef_config[:ssl_verify] = value != :verify_none
46
48
  end
47
49
 
48
50
  def method_missing(*args)
@@ -52,50 +54,35 @@ module Fluent
52
54
 
53
55
  def configure(conf)
54
56
  super
55
- @config = {}
56
57
  if @config_file
57
- @config = @config.merge(ChefConfig.load_file(@config_file))
58
+ @chef_config = ChefConfig.load_file(@config_file).to_hash
59
+ else
60
+ @chef_config = {}
58
61
  end
59
62
  if @chef_server_url
60
- @config[:endpoint] = @chef_server_url
63
+ @chef_config[:endpoint] = @chef_server_url
61
64
  end
62
65
  if @node_name
63
- @config[:client] = value
66
+ @chef_config[:client] = value
64
67
  end
65
68
  if @client_key
66
- @config[:key] = ::File.read(@client_key)
69
+ @chef_config[:key] = ::File.read(@client_key)
67
70
  end
68
71
  end
69
72
 
70
73
  def start
71
- @running = true
72
- @thread = ::Thread.new(&method(:run))
73
- end
74
-
75
- def shutdown
76
- @running = false
77
- @thread.join
74
+ thread_create(:chef_api, &method(:run))
75
+ super
78
76
  end
79
77
 
80
78
  def run
81
- connection = ChefAPI::Connection.new(@config.dup)
82
- next_run = ::Time.new
83
- while @running
84
- if ::Time.new < next_run
85
- sleep(1)
79
+ super
80
+ @connection = ChefAPI::Connection.new(@chef_config.dup)
81
+ timer_execute(:chef_api_input, @check_interval) do
82
+ if @monitor_multi
83
+ run_once(connection)
86
84
  else
87
- begin
88
- if @monitor_multi
89
- run_once(connection)
90
- else
91
- run_once_single(connection)
92
- end
93
- rescue => error
94
- $log.warn("failed to fetch metrics: #{error.class}: #{error.message}")
95
- next
96
- ensure
97
- next_run = ::Time.new + @check_interval
98
- end
85
+ run_once_single(connection)
99
86
  end
100
87
  end
101
88
  end
@@ -114,7 +101,7 @@ module Fluent
114
101
  else
115
102
  nodes = connection.nodes
116
103
  end
117
- Engine.emit("#{@tag}.nodes", Engine.now, data.merge({"value" => nodes.count}))
104
+ router.emit("#{@tag}.nodes", Engine.now, data.merge({"value" => nodes.count}))
118
105
  begin
119
106
  nodes.instance_eval do
120
107
  if Hash === @collection
@@ -122,7 +109,7 @@ module Fluent
122
109
  end
123
110
  end
124
111
  rescue => error
125
- $log.warn("failed to shuffle nodes: #{error.class}: #{error.message}")
112
+ log.warn("failed to shuffle nodes", error: error)
126
113
  end
127
114
  nodes.each do |node|
128
115
  emit_node_metrics(node, data)
@@ -131,14 +118,14 @@ module Fluent
131
118
 
132
119
  def emit_node_metrics(node, data)
133
120
  begin
134
- Engine.emit("#{@tag}.run_list", Engine.now, data.merge({"value" => node.run_list.length, "node" => node.name}))
121
+ router.emit("#{@tag}.run_list", Engine.now, data.merge({"value" => node.run_list.length, "node" => node.name}))
135
122
  if node.automatic["ohai_time"]
136
123
  ohai_time = node.automatic["ohai_time"].to_i
137
- Engine.emit("#{@tag}.ohai_time", Engine.now, data.merge({"value" => ohai_time, "node" => node.name}))
138
- Engine.emit("#{@tag}.behind_seconds", Engine.now, data.merge({"value" => Time.new.to_i - ohai_time, "node" => node.name}))
124
+ router.emit("#{@tag}.ohai_time", Engine.now, data.merge({"value" => ohai_time, "node" => node.name}))
125
+ router.emit("#{@tag}.behind_seconds", Engine.now, data.merge({"value" => Time.new.to_i - ohai_time, "node" => node.name}))
139
126
  end
140
127
  rescue => error
141
- $log.warn("failed to fetch metrics from node: #{node.name}: #{error.class}: #{error.message}")
128
+ log.warn("failed to fetch metrics from node: #{node.name}", error: error)
142
129
  end
143
130
  end
144
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-chef-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: chef-api
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -99,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.11
102
+ rubygems_version: 3.0.3
104
103
  signing_key:
105
104
  specification_version: 4
106
105
  summary: A fluentd plugin for Chef's API