fluent-plugin-factor 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/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +116 -0
- data/Rakefile +10 -0
- data/fluent-plugin-factor.gemspec +25 -0
- data/lib/fluent/plugin/in_factor.rb +166 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_in_factor.rb +21 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6d09ab6ecb1a70333ffa855c88600fc1a010291
|
4
|
+
data.tar.gz: dd54b28f7eab3d95a47bb78d5889f2c1d501618e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a971e0b8c5811fcaee5bfea3eeca9b3ba39c3e9ca4603201184e253614d7986e300eefa8ee1f7ba970b844cfc7553bdf0864b1ca37434e6f8e444339bec0918
|
7
|
+
data.tar.gz: 48acc468e1a900598ad4efa01b5515cd8ab9e565390ee53760b3de7272a6a5a25cb04ef08a7b1a50d725b55e6f017e847881bb2f97d757cf69ba34a6d90522fc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 eramuk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# fluent-plugin-factor
|
2
|
+
|
3
|
+
## Requirements
|
4
|
+
|
5
|
+
| fluent-plugin-factor | fluentd |
|
6
|
+
|----------------------|------------|
|
7
|
+
| >= 1.0.0 | >= v0.14.0 |
|
8
|
+
| < 1.0.0 | < v0.14.0 |
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
```
|
12
|
+
gem install fluent-plugin-factor
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
Example:
|
17
|
+
```
|
18
|
+
<source>
|
19
|
+
@type factor
|
20
|
+
tag factor
|
21
|
+
run_at_start
|
22
|
+
run_interval 1h
|
23
|
+
</source>
|
24
|
+
```
|
25
|
+
|
26
|
+
output as follows every hour:
|
27
|
+
```
|
28
|
+
factor: {
|
29
|
+
"hostname": "test-machine",
|
30
|
+
"operatingsystem": {
|
31
|
+
"name": "CentOS",
|
32
|
+
"version": "6.8",
|
33
|
+
"family": "RedHat"
|
34
|
+
},
|
35
|
+
"kernel": {
|
36
|
+
"name": "Linux",
|
37
|
+
"release": "2.6.32-642.11.1.el6.x86_64"
|
38
|
+
},
|
39
|
+
"processors": {
|
40
|
+
"models": [
|
41
|
+
"Intel(R) Xeon(R) CPU X5650 @ 2.67GHz",
|
42
|
+
"Intel(R) Xeon(R) CPU X5650 @ 2.67GHz"
|
43
|
+
],
|
44
|
+
"count": 2,
|
45
|
+
"physicalcount": 1
|
46
|
+
},
|
47
|
+
"memory": {
|
48
|
+
"size": "995.95"
|
49
|
+
},
|
50
|
+
"volumes": [
|
51
|
+
{
|
52
|
+
"name": "sda",
|
53
|
+
"size": 10
|
54
|
+
}
|
55
|
+
],
|
56
|
+
"interfaces": [
|
57
|
+
{
|
58
|
+
"name": "eth0",
|
59
|
+
"ipaddress": "10.8.0.201",
|
60
|
+
"netmask": "255.255.252.0",
|
61
|
+
"macaddress": "00:0C:29:C5:26:8A"
|
62
|
+
}
|
63
|
+
],
|
64
|
+
"is_virtual": true
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
## Configuration
|
69
|
+
|
70
|
+
### tag (required)
|
71
|
+
The tag of the event.
|
72
|
+
|
73
|
+
### run_interval
|
74
|
+
The gathering interval. If enable this option, the gathering function is not execute when starting fluentd. If you want, enable `run_at_start` option.
|
75
|
+
|
76
|
+
### run_at_start
|
77
|
+
If set to true, gathering at start fluentd.
|
78
|
+
|
79
|
+
### run_at_shutdown
|
80
|
+
If set to true, gathering at shutdown fluentd.
|
81
|
+
|
82
|
+
### \<factors\>
|
83
|
+
If you want to gather only specific factor, you can use `<factors>` section.
|
84
|
+
```
|
85
|
+
<source>
|
86
|
+
@type factor
|
87
|
+
tag factor
|
88
|
+
<factors>
|
89
|
+
memory true
|
90
|
+
volumes true
|
91
|
+
</factors>
|
92
|
+
</source>
|
93
|
+
```
|
94
|
+
In this case, the output is only memory and volumes.
|
95
|
+
```
|
96
|
+
factor: {
|
97
|
+
"memory": {
|
98
|
+
"size": "995.95"
|
99
|
+
},
|
100
|
+
"volumes": [
|
101
|
+
{
|
102
|
+
"name": "sda",
|
103
|
+
"size": 10
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
```
|
108
|
+
The available keys as follows:
|
109
|
+
- hostname
|
110
|
+
- operatingsystem
|
111
|
+
- kernel
|
112
|
+
- processors
|
113
|
+
- memory
|
114
|
+
- volumes
|
115
|
+
- interfaces
|
116
|
+
- is_virtual
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: 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 |gem|
|
6
|
+
gem.name = "fluent-plugin-factor"
|
7
|
+
gem.version = "0.1.0"
|
8
|
+
gem.authors = ["Yuki Kuwabara"]
|
9
|
+
gem.email = ["eramuk@gmail.com"]
|
10
|
+
gem.summary = "input plugin for gathering factor"
|
11
|
+
gem.description = gem.summary
|
12
|
+
gem.homepage = "https://github.com/eramuk/fluent-plugin-factor"
|
13
|
+
gem.licenses = ["MIT"]
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "fluentd", "~> 0.12.0"
|
21
|
+
gem.add_runtime_dependency "facter", "~> 2.4", ">= 2.4.6"
|
22
|
+
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "test-unit"
|
25
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require "fluent/input"
|
2
|
+
require "fluent/time"
|
3
|
+
require "fluent/timezone"
|
4
|
+
require "fluent/config/error"
|
5
|
+
require "facter"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
module Fluent
|
9
|
+
class FactorInput < Input
|
10
|
+
Plugin.register_input('factor', self)
|
11
|
+
|
12
|
+
config_param :tag, :string
|
13
|
+
config_param :run_interval, :time, default: nil
|
14
|
+
config_param :run_at_start, :bool, default: nil
|
15
|
+
config_param :run_at_shutdown, :bool, default: nil
|
16
|
+
config_section :factors, multi: false do
|
17
|
+
config_param :hostname, :bool, default: false
|
18
|
+
config_param :operatingsystem, :bool, default: false
|
19
|
+
config_param :kernel, :bool, default: false
|
20
|
+
config_param :processors, :bool, default: false
|
21
|
+
config_param :memory, :bool, default: false
|
22
|
+
config_param :volumes, :bool, default: false
|
23
|
+
config_param :interfaces, :bool, default: false
|
24
|
+
config_param :is_virtual, :bool, default: false
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure(conf)
|
28
|
+
super
|
29
|
+
|
30
|
+
if !@run_interval && @run_at_start
|
31
|
+
raise ConfigError, "'run_at_start' option needs 'run_interval' option"
|
32
|
+
end
|
33
|
+
|
34
|
+
factor_keys = [
|
35
|
+
"hostname",
|
36
|
+
"operatingsystem",
|
37
|
+
"kernel",
|
38
|
+
"processors",
|
39
|
+
"memory",
|
40
|
+
"volumes",
|
41
|
+
"interfaces",
|
42
|
+
"is_virtual",
|
43
|
+
]
|
44
|
+
|
45
|
+
@factors = @factors.to_h
|
46
|
+
|
47
|
+
if @factors.empty?
|
48
|
+
factor_keys.each do |key|
|
49
|
+
@factors[key] = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if @factors.select { |k,v| v == true }.empty?
|
54
|
+
raise ConfigError, "one or more factor are required"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def start
|
59
|
+
super
|
60
|
+
if @run_interval
|
61
|
+
@finished = false
|
62
|
+
@thread = Thread.new(&method(:run_periodic))
|
63
|
+
else
|
64
|
+
@thread = Thread.new(&method(:run))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def before_shutdown
|
69
|
+
super
|
70
|
+
gather_factor if @run_at_shutdown
|
71
|
+
end
|
72
|
+
|
73
|
+
def shutdown
|
74
|
+
super
|
75
|
+
@thread.terminate
|
76
|
+
@thread.join
|
77
|
+
end
|
78
|
+
|
79
|
+
def run
|
80
|
+
gather_factor
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_periodic
|
84
|
+
gather_factor if @run_at_start
|
85
|
+
while true
|
86
|
+
sleep @run_interval
|
87
|
+
gather_factor
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def gather_factor
|
92
|
+
begin
|
93
|
+
record = {}
|
94
|
+
@factors.each do |factor, enabled|
|
95
|
+
record[factor] = send(factor) if enabled
|
96
|
+
end
|
97
|
+
router.emit(@tag, Engine.now, record)
|
98
|
+
rescue => e
|
99
|
+
router.emit_error_event(@tag, Engine.now, record, e)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def hostname
|
104
|
+
Facter.value(:hostname)
|
105
|
+
end
|
106
|
+
|
107
|
+
def operatingsystem
|
108
|
+
{
|
109
|
+
"name" => Facter.value(:operatingsystem),
|
110
|
+
"version" => Facter.value(:operatingsystemrelease),
|
111
|
+
"family" => Facter.value(:osfamily),
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def kernel
|
116
|
+
{
|
117
|
+
"name" => Facter.value(:kernel),
|
118
|
+
"release" => Facter.value(:kernelrelease),
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def processors
|
123
|
+
Facter.value(:processors)
|
124
|
+
end
|
125
|
+
|
126
|
+
def memory
|
127
|
+
{
|
128
|
+
"size" => Facter.value(:memorysize_mb )
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
def volumes
|
133
|
+
volumes = []
|
134
|
+
blockdevice_names = Facter.value(:blockdevices).split(/,/)
|
135
|
+
blockdevice_names.each do |device_name|
|
136
|
+
next if device_name !~ /(hd.*|sd.*|md.*)/
|
137
|
+
volumes.push({
|
138
|
+
"name" => device_name,
|
139
|
+
"size" => Facter.value("blockdevice_#{device_name}_size") / 1024 / 1024 / 1024,
|
140
|
+
})
|
141
|
+
end
|
142
|
+
volumes
|
143
|
+
end
|
144
|
+
|
145
|
+
def interfaces
|
146
|
+
interfaces = []
|
147
|
+
interface_names = Facter.value(:interfaces).split(/,/)
|
148
|
+
if interface_names
|
149
|
+
interface_names.each do |if_name|
|
150
|
+
next if if_name == "lo"
|
151
|
+
interfaces.push({
|
152
|
+
"name" => if_name,
|
153
|
+
"ipaddress" => Facter.value("ipaddress_#{if_name}"),
|
154
|
+
"netmask" => Facter.value("netmask_#{if_name}"),
|
155
|
+
"macaddress" => Facter.value("macaddress_#{if_name}"),
|
156
|
+
})
|
157
|
+
end
|
158
|
+
end
|
159
|
+
interfaces
|
160
|
+
end
|
161
|
+
|
162
|
+
def is_virtual
|
163
|
+
Facter.value(:is_virtual)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/in_factor'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class FactorInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %{
|
9
|
+
tag test
|
10
|
+
}
|
11
|
+
|
12
|
+
def create_driver(conf = CONFIG)
|
13
|
+
Fluent::Test::InputTestDriver.new(Fluent::FactorInput).configure(conf)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_emit
|
17
|
+
d = create_driver
|
18
|
+
d.run
|
19
|
+
p d.emits
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-factor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuki Kuwabara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-22 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.12.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: facter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.4.6
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.4'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.4.6
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: test-unit
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: input plugin for gathering factor
|
76
|
+
email:
|
77
|
+
- eramuk@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- fluent-plugin-factor.gemspec
|
87
|
+
- lib/fluent/plugin/in_factor.rb
|
88
|
+
- test/helper.rb
|
89
|
+
- test/plugin/test_in_factor.rb
|
90
|
+
homepage: https://github.com/eramuk/fluent-plugin-factor
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: input plugin for gathering factor
|
114
|
+
test_files:
|
115
|
+
- test/helper.rb
|
116
|
+
- test/plugin/test_in_factor.rb
|