fluent-plugin-chef-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +14 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/fluent-plugin-chef-api.gemspec +25 -0
- data/lib/fluent/plugin/in_chef_api.rb +78 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5325782f5a23cb6584cbdeb9a6ab7faa65620917
|
4
|
+
data.tar.gz: 9428717dc18abf198a3a4827dfc08bdb7b6c5e8d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49eaaad8744e1ab70b9272cb2bb00e6ced26cc5eb5eaf0fbcf443b1258743d4593affee24c41112779fb5509a451e792e1037b1ab0a50f923d6c44ce767130c4
|
7
|
+
data.tar.gz: 562d55aa0a9887443e1610a2cac3b9c4c0137bab3e2392ab4cee68b9af61e92525327e82aa0e7db2a7f68fbcb2e672a61a2fc29aac0a427426de6417b59db2c5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (C) 2015 Yamashita, Yuu
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# fluent-plugin-chef-api
|
2
|
+
|
3
|
+
A fluentd plugin implementation to fetch metrics from Chef API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fluent-plugin-chef-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-plugin-chef-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( https://github.com/yyuu/fluent-plugin-chef-api/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -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-chef-api"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Yamashita Yuu"]
|
9
|
+
spec.email = ["peek824545201@gmail.com"]
|
10
|
+
spec.license = "Apache-2.0"
|
11
|
+
|
12
|
+
spec.summary = %q{A fluentd plugin for Chef's API}
|
13
|
+
spec.description = %q{A fluentd plugin for Chef's API.}
|
14
|
+
spec.homepage = "https://github.com/yyuu/fluent-plugin-chef-api"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency "fluentd"
|
24
|
+
spec.add_dependency "chef-api", "~> 0.5.0"
|
25
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class ChefAPIInput < Input
|
5
|
+
Plugin.register_input("chef_api", self)
|
6
|
+
|
7
|
+
config_param :check_interval, :integer, :default => 60
|
8
|
+
config_param :chef_server_url, :string, :default => nil
|
9
|
+
config_param :client_key, :string, :default => nil
|
10
|
+
config_param :config_file, :string, :default => "/etc/chef/client.rb"
|
11
|
+
config_param :node_name, :string, :default => nil
|
12
|
+
config_param :tag, :string, :default => "chef_api"
|
13
|
+
config_param :chef_environment, :string, :default => nil
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
require "chef-api"
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
@running = true
|
26
|
+
@thread = ::Thread.new(&method(:run))
|
27
|
+
end
|
28
|
+
|
29
|
+
def shutdown
|
30
|
+
@running = false
|
31
|
+
@thread.join
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
connection = ChefAPI::Connection.new(
|
36
|
+
:endpoint => @chef_server_url,
|
37
|
+
:client => @node_name,
|
38
|
+
:key => ::File.read(@client_key),
|
39
|
+
)
|
40
|
+
next_run = ::Time.new
|
41
|
+
while @running
|
42
|
+
if ::Time.new < next_run
|
43
|
+
sleep(1)
|
44
|
+
else
|
45
|
+
begin
|
46
|
+
run_once(connection)
|
47
|
+
rescue => error
|
48
|
+
$log.warn("failed to fetch metrics: #{error.class}: #{error.message}")
|
49
|
+
next
|
50
|
+
ensure
|
51
|
+
next_run = ::Time.new + @check_interval
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_once(connection)
|
58
|
+
if @chef_environment
|
59
|
+
nodes = connection.environments.fetch(@chef_environment).nodes
|
60
|
+
data = {"chef_environment" => @chef_environment}
|
61
|
+
else
|
62
|
+
nodes = connection.nodes
|
63
|
+
data = {}
|
64
|
+
end
|
65
|
+
Engine.emit("#{@tag}.nodes", Engine.now, data.merge({"value" => nodes.count}))
|
66
|
+
nodes.each do |node|
|
67
|
+
begin
|
68
|
+
Engine.emit("#{@tag}.run_list", Engine.now, data.merge({"value" => node.run_list.length, "node" => node.name}))
|
69
|
+
ohai_time = node.automatic.fetch("ohai_time")
|
70
|
+
Engine.emit("#{@tag}.ohai_time", Engine.now, data.merge({"value" => ohai_time, "node" => node.name}))
|
71
|
+
Engine.emit("#{@tag}.behind_seconds", Engine.now, data.merge({"value" => Time.new.to_i - ohai_time, "node" => node.name}))
|
72
|
+
rescue => error
|
73
|
+
$log.warn("failed to fetch metrics from node: #{node.name}: #{error.class}: #{error.message}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-chef-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yamashita Yuu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-02 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
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'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chef-api
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.0
|
69
|
+
description: A fluentd plugin for Chef's API.
|
70
|
+
email:
|
71
|
+
- peek824545201@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-chef-api.gemspec
|
82
|
+
- lib/fluent/plugin/in_chef_api.rb
|
83
|
+
homepage: https://github.com/yyuu/fluent-plugin-chef-api
|
84
|
+
licenses:
|
85
|
+
- Apache-2.0
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.4.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: A fluentd plugin for Chef's API
|
107
|
+
test_files: []
|