fluent-plugin-monitor-agent-modified 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/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LISENCE +202 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/fluent-plugin-monitor-agent-modified.gemspec +45 -0
- data/lib/.DS_Store +0 -0
- data/lib/fluent/.DS_Store +0 -0
- data/lib/fluent/plugin/.DS_Store +0 -0
- data/lib/fluent/plugin/in_monitor_agent_modified.rb +416 -0
- data/lib/fluent/version.rb +3 -0
- metadata +209 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf81903f50faa92661d7b83dca447b00a4ca2ad3
|
4
|
+
data.tar.gz: 7e9ecec113fd61ce36168fe85cd344539a6eabdc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 843a899a8b67bd33c905a61cc1230f80356e6e70a5c2b5284fdee4fdff8e47fa3857bf343e22ae92227720090a9b67179f8c266fb33678cfb1ff2f7a93b4c735
|
7
|
+
data.tar.gz: f380da14f63def6b7a64299da49df058142480f78f58f60ae4a10e47f66c7b4b253cf1b28fd6211d71093f26a2ef10b9235e9461fe4e6fe8ee6b734072070ca0
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LISENCE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2011-2018 Fluentd Authors
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# fluent-plugin-monitor-agent-modified
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
This Fluentd plugin is available as the `fluent-plugin-monitor-agent-modified` gem from RubyGems.
|
8
|
+
|
9
|
+
gem install fluent-plugin-monitor-agent-modified
|
10
|
+
|
11
|
+
Or you can install this plugin for [td-agent][td-agent] as:
|
12
|
+
|
13
|
+
td-agent-gem install fluent-plugin-monitor-agent-modified
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
TODO: Write usage instructions here
|
18
|
+
|
19
|
+
## Development
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-plugin-monitor-agent-modified.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "fluent/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-monitor-agent-modified"
|
7
|
+
spec.version = Fluent::VERSION
|
8
|
+
spec.authors = ["wanfeng.hu"]
|
9
|
+
spec.email = ["wanfeng.hu@ihandysoft.com"]
|
10
|
+
spec.license = "Apache-2.0"
|
11
|
+
|
12
|
+
spec.summary = %q{Outputs monitor informations for fluentd}
|
13
|
+
spec.description = %q{Modified version of default in_monitor_agent in fluentd. It can monitor number of emitted records during emit_interval when tag is configured.}
|
14
|
+
spec.homepage = "https://github.com/BlackNight95/fluent-plugin-monitor-agent-modified"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
# build gem for a certain platform. see also Rakefile
|
26
|
+
fake_platform = ENV['GEM_BUILD_FAKE_PLATFORM'].to_s
|
27
|
+
spec.platform = fake_platform unless fake_platform.empty?
|
28
|
+
if /mswin|mingw/ =~ fake_platform || (/mswin|mingw/ =~ RUBY_PLATFORM && fake_platform.empty?)
|
29
|
+
spec.add_runtime_dependency("win32-service", ["~> 0.8.3"])
|
30
|
+
spec.add_runtime_dependency("win32-ipc", ["~> 0.6.1"])
|
31
|
+
spec.add_runtime_dependency("win32-event", ["~> 0.6.1"])
|
32
|
+
spec.add_runtime_dependency("windows-pr", ["~> 1.2.5"])
|
33
|
+
end
|
34
|
+
|
35
|
+
spec.add_dependency "fluentd", ">= 0.14.10", "< 2"
|
36
|
+
spec.add_development_dependency("rake", ["~> 11.0"])
|
37
|
+
spec.add_development_dependency("flexmock", ["~> 2.0"])
|
38
|
+
spec.add_development_dependency("parallel_tests", ["~> 0.15.3"])
|
39
|
+
spec.add_development_dependency("simplecov", ["~> 0.7"])
|
40
|
+
spec.add_development_dependency("rr", ["~> 1.0"])
|
41
|
+
spec.add_development_dependency("timecop", ["~> 0.3"])
|
42
|
+
spec.add_development_dependency("test-unit", ["~> 3.2"])
|
43
|
+
spec.add_development_dependency("test-unit-rr", ["~> 1.0"])
|
44
|
+
spec.add_development_dependency("oj", [">= 2.14", "< 4"])
|
45
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,416 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'json'
|
18
|
+
require 'webrick'
|
19
|
+
require 'cgi'
|
20
|
+
|
21
|
+
require 'fluent/config/types'
|
22
|
+
require 'fluent/plugin/input'
|
23
|
+
require 'fluent/plugin/output'
|
24
|
+
require 'fluent/plugin/multi_output'
|
25
|
+
require 'fluent/plugin/filter'
|
26
|
+
|
27
|
+
module Fluent::Plugin
|
28
|
+
class MonitorAgentInput < Input
|
29
|
+
Fluent::Plugin.register_input('monitor_agent_modified', self)
|
30
|
+
|
31
|
+
helpers :timer, :thread, :http_server
|
32
|
+
|
33
|
+
desc 'The address to bind to.'
|
34
|
+
config_param :bind, :string, default: '0.0.0.0'
|
35
|
+
desc 'The port to listen to.'
|
36
|
+
config_param :port, :integer, default: 24220
|
37
|
+
desc 'The tag with which internal metrics are emitted.'
|
38
|
+
config_param :tag, :string, default: nil
|
39
|
+
desc 'Determine the rate to emit internal metrics as events.'
|
40
|
+
config_param :emit_interval, :time, default: 60
|
41
|
+
desc 'Determine whether to include the config information.'
|
42
|
+
config_param :include_config, :bool, default: true
|
43
|
+
desc 'Determine whether to include the retry information.'
|
44
|
+
config_param :include_retry, :bool, default: true
|
45
|
+
|
46
|
+
class APIHandler
|
47
|
+
def initialize(agent)
|
48
|
+
@agent = agent
|
49
|
+
end
|
50
|
+
|
51
|
+
def plugins_ltsv(req)
|
52
|
+
list = build_object(build_option(req))
|
53
|
+
|
54
|
+
render_ltsv(list)
|
55
|
+
end
|
56
|
+
|
57
|
+
def plugins_json(req)
|
58
|
+
opts = build_option(req)
|
59
|
+
obj = build_object(opts)
|
60
|
+
|
61
|
+
render_json({ 'plugins' => obj }, pretty_json: opts[:pretty_json])
|
62
|
+
end
|
63
|
+
|
64
|
+
def config_ltsv(_req)
|
65
|
+
obj = {
|
66
|
+
'pid' => Process.pid,
|
67
|
+
'ppid' => Process.ppid
|
68
|
+
}.merge(@agent.fluentd_opts)
|
69
|
+
|
70
|
+
render_ltsv([obj])
|
71
|
+
end
|
72
|
+
|
73
|
+
def config_json(req)
|
74
|
+
obj = {
|
75
|
+
'pid' => Process.pid,
|
76
|
+
'ppid' => Process.ppid
|
77
|
+
}.merge(@agent.fluentd_opts)
|
78
|
+
opts = build_option(req)
|
79
|
+
|
80
|
+
render_json(obj, pretty_json: opts[:pretty_json])
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def render_error_json(code:, msg:, pretty_json: nil, **additional_params)
|
86
|
+
resp = additional_params.merge('message' => msg)
|
87
|
+
render_json(resp, code: code, pretty_json: pretty_json)
|
88
|
+
end
|
89
|
+
|
90
|
+
def render_json(obj, code: 200, pretty_json: nil)
|
91
|
+
body =
|
92
|
+
if pretty_json
|
93
|
+
JSON.pretty_generate(obj)
|
94
|
+
else
|
95
|
+
obj.to_json
|
96
|
+
end
|
97
|
+
|
98
|
+
[code, { 'Content-Type' => 'application/json' }, body]
|
99
|
+
end
|
100
|
+
|
101
|
+
def render_ltsv(obj, code: 200)
|
102
|
+
normalized = JSON.parse(obj.to_json)
|
103
|
+
text = ''
|
104
|
+
normalized.each do |hash|
|
105
|
+
row = []
|
106
|
+
hash.each do |k, v|
|
107
|
+
if v.is_a?(Array)
|
108
|
+
row << "#{k}:#{v.join(',')}"
|
109
|
+
elsif v.is_a?(Hash)
|
110
|
+
next
|
111
|
+
else
|
112
|
+
row << "#{k}:#{v}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
text << row.join("\t") << "\n"
|
117
|
+
end
|
118
|
+
|
119
|
+
[code, { 'Content-Type' => 'text/plain' }, text]
|
120
|
+
end
|
121
|
+
|
122
|
+
def build_object(opts)
|
123
|
+
qs = opts[:query]
|
124
|
+
if tag = qs['tag'.freeze].first
|
125
|
+
# ?tag= to search an output plugin by match pattern
|
126
|
+
if obj = @agent.plugin_info_by_tag(tag, opts)
|
127
|
+
list = [obj]
|
128
|
+
else
|
129
|
+
list = []
|
130
|
+
end
|
131
|
+
elsif plugin_id = (qs['@id'.freeze].first || qs['id'.freeze].first)
|
132
|
+
# ?@id= to search a plugin by 'id <plugin_id>' config param
|
133
|
+
if obj = @agent.plugin_info_by_id(plugin_id, opts)
|
134
|
+
list = [obj]
|
135
|
+
else
|
136
|
+
list = []
|
137
|
+
end
|
138
|
+
elsif plugin_type = (qs['@type'.freeze].first || qs['type'.freeze].first)
|
139
|
+
# ?@type= to search plugins by 'type <type>' config param
|
140
|
+
list = @agent.plugins_info_by_type(plugin_type, opts)
|
141
|
+
else
|
142
|
+
# otherwise show all plugins
|
143
|
+
list = @agent.plugins_info_all(opts)
|
144
|
+
end
|
145
|
+
|
146
|
+
list
|
147
|
+
end
|
148
|
+
|
149
|
+
def build_option(req)
|
150
|
+
qs = Hash.new { |_, _| [] }
|
151
|
+
# parse ?=query string
|
152
|
+
if req.query_string
|
153
|
+
qs.merge!(CGI.parse(req.query_string))
|
154
|
+
end
|
155
|
+
|
156
|
+
# if ?debug=1 is set, set :with_debug_info for get_monitor_info
|
157
|
+
# and :pretty_json for render_json_error
|
158
|
+
opts = { query: qs }
|
159
|
+
if qs['debug'.freeze].first
|
160
|
+
opts[:with_debug_info] = true
|
161
|
+
opts[:pretty_json] = true
|
162
|
+
end
|
163
|
+
|
164
|
+
if ivars = qs['with_ivars'.freeze].first
|
165
|
+
opts[:ivars] = ivars.split(',')
|
166
|
+
end
|
167
|
+
|
168
|
+
if with_config = qs['with_config'.freeze].first
|
169
|
+
opts[:with_config] = Fluent::Config.bool_value(with_config)
|
170
|
+
else
|
171
|
+
opts[:with_config] = @agent.include_config
|
172
|
+
end
|
173
|
+
|
174
|
+
if with_retry = qs['with_retry'.freeze].first
|
175
|
+
opts[:with_retry] = Fluent::Config.bool_value(with_retry)
|
176
|
+
else
|
177
|
+
opts[:with_retry] = @agent.include_retry
|
178
|
+
end
|
179
|
+
|
180
|
+
opts
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def initialize
|
185
|
+
super
|
186
|
+
|
187
|
+
@first_warn = false
|
188
|
+
end
|
189
|
+
|
190
|
+
def configure(conf)
|
191
|
+
super
|
192
|
+
@port += fluentd_worker_id
|
193
|
+
end
|
194
|
+
|
195
|
+
def multi_workers_ready?
|
196
|
+
true
|
197
|
+
end
|
198
|
+
|
199
|
+
class NotFoundJson
|
200
|
+
BODY = { 'message' => 'Not found' }.to_json
|
201
|
+
def self.call(_req)
|
202
|
+
[404, { 'Content-Type' => 'application/json' }, BODY]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def start
|
207
|
+
super
|
208
|
+
@old = nil
|
209
|
+
|
210
|
+
log.debug "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins for worker#{fluentd_worker_id}"
|
211
|
+
api_handler = APIHandler.new(self)
|
212
|
+
create_http_server(addr: @bind, port: @port, logger: log, default_app: NotFoundJson) do |serv|
|
213
|
+
serv.get('/api/plugins') { |req| api_handler.plugins_ltsv(req) }
|
214
|
+
serv.get('/api/plugins.json') { |req| api_handler.plugins_json(req) }
|
215
|
+
serv.get('/api/config') { |req| api_handler.config_ltsv(req) }
|
216
|
+
serv.get('/api/config.json') { |req| api_handler.config_json(req) }
|
217
|
+
end
|
218
|
+
|
219
|
+
if @tag
|
220
|
+
log.debug "tag parameter is specified. Emit plugins info to '#{@tag}'"
|
221
|
+
opts = {with_config: false, with_retry: false}
|
222
|
+
if @old.nil?
|
223
|
+
@old = plugins_info_all(opts)
|
224
|
+
end
|
225
|
+
timer_execute(:in_monitor_agent_emit, @emit_interval, repeat: true) {
|
226
|
+
es = Fluent::MultiEventStream.new
|
227
|
+
now = Fluent::Engine.now
|
228
|
+
@new = plugins_info_all(opts)
|
229
|
+
@new.each_with_index do |record, index|
|
230
|
+
if record["emit_records"]
|
231
|
+
record["records"] = record["emit_records"] - @old[index]["emit_records"]
|
232
|
+
end
|
233
|
+
es.add(now, record)
|
234
|
+
end
|
235
|
+
@old = @new
|
236
|
+
router.emit_stream(@tag, es)
|
237
|
+
}
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# They are deprecated but remain for compatibility
|
242
|
+
MONITOR_INFO = {
|
243
|
+
'output_plugin' => ->(){ is_a?(::Fluent::Plugin::Output) },
|
244
|
+
'buffer_queue_length' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.queue.size },
|
245
|
+
'buffer_timekeys' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.timekeys },
|
246
|
+
'buffer_total_queued_size' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.stage_size + @buffer.queue_size },
|
247
|
+
'retry_count' => ->(){ instance_variable_defined?(:@num_errors) ? @num_errors : nil },
|
248
|
+
}
|
249
|
+
|
250
|
+
def all_plugins
|
251
|
+
array = []
|
252
|
+
|
253
|
+
# get all input plugins
|
254
|
+
array.concat Fluent::Engine.root_agent.inputs
|
255
|
+
|
256
|
+
# get all output plugins
|
257
|
+
array.concat Fluent::Engine.root_agent.outputs
|
258
|
+
|
259
|
+
# get all filter plugins
|
260
|
+
array.concat Fluent::Engine.root_agent.filters
|
261
|
+
|
262
|
+
Fluent::Engine.root_agent.labels.each { |name, l|
|
263
|
+
# TODO: Add label name to outputs / filters for identifing plugins
|
264
|
+
array.concat l.outputs
|
265
|
+
array.concat l.filters
|
266
|
+
}
|
267
|
+
|
268
|
+
array
|
269
|
+
end
|
270
|
+
|
271
|
+
# try to match the tag and get the info from the matched output plugin
|
272
|
+
# TODO: Support output in label
|
273
|
+
def plugin_info_by_tag(tag, opts={})
|
274
|
+
matches = Fluent::Engine.root_agent.event_router.instance_variable_get(:@match_rules)
|
275
|
+
matches.each { |rule|
|
276
|
+
if rule.match?(tag)
|
277
|
+
if rule.collector.is_a?(Fluent::Plugin::Output) || rule.collector.is_a?(Fluent::Output)
|
278
|
+
return get_monitor_info(rule.collector, opts)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
}
|
282
|
+
nil
|
283
|
+
end
|
284
|
+
|
285
|
+
# search a plugin by plugin_id
|
286
|
+
def plugin_info_by_id(plugin_id, opts={})
|
287
|
+
found = all_plugins.find {|pe|
|
288
|
+
pe.respond_to?(:plugin_id) && pe.plugin_id.to_s == plugin_id
|
289
|
+
}
|
290
|
+
if found
|
291
|
+
get_monitor_info(found, opts)
|
292
|
+
else
|
293
|
+
nil
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
# This method returns an array because
|
298
|
+
# multiple plugins could have the same type
|
299
|
+
def plugins_info_by_type(type, opts={})
|
300
|
+
array = all_plugins.select {|pe|
|
301
|
+
(pe.config['@type'] == type) rescue nil
|
302
|
+
}
|
303
|
+
array.map {|pe|
|
304
|
+
get_monitor_info(pe, opts)
|
305
|
+
}
|
306
|
+
end
|
307
|
+
|
308
|
+
def plugins_info_all(opts={})
|
309
|
+
all_plugins.map {|pe|
|
310
|
+
get_monitor_info(pe, opts)
|
311
|
+
}
|
312
|
+
end
|
313
|
+
|
314
|
+
IGNORE_ATTRIBUTES = %i(@config_root_section @config @masked_config)
|
315
|
+
|
316
|
+
# get monitor info from the plugin `pe` and return a hash object
|
317
|
+
def get_monitor_info(pe, opts={})
|
318
|
+
obj = {}
|
319
|
+
|
320
|
+
# Common plugin information
|
321
|
+
obj['plugin_id'] = pe.plugin_id
|
322
|
+
obj['plugin_category'] = plugin_category(pe)
|
323
|
+
obj['type'] = pe.config['@type']
|
324
|
+
obj['config'] = pe.config if opts[:with_config]
|
325
|
+
|
326
|
+
# run MONITOR_INFO in plugins' instance context and store the info to obj
|
327
|
+
MONITOR_INFO.each_pair {|key,code|
|
328
|
+
begin
|
329
|
+
catch(:skip) do
|
330
|
+
obj[key] = pe.instance_exec(&code)
|
331
|
+
end
|
332
|
+
rescue NoMethodError => e
|
333
|
+
unless @first_warn
|
334
|
+
log.error "NoMethodError in monitoring plugins", key: key, plugin: pe.class, error: e
|
335
|
+
log.error_backtrace
|
336
|
+
@first_warn = true
|
337
|
+
end
|
338
|
+
rescue => e
|
339
|
+
log.warn "unexpected error in monitoring plugins", key: key, plugin: pe.class, error: e
|
340
|
+
end
|
341
|
+
}
|
342
|
+
|
343
|
+
if pe.respond_to?(:statistics)
|
344
|
+
obj.merge!(pe.statistics['output'] || {})
|
345
|
+
end
|
346
|
+
|
347
|
+
obj['retry'] = get_retry_info(pe.retry) if opts[:with_retry] and pe.instance_variable_defined?(:@retry)
|
348
|
+
|
349
|
+
# include all instance variables if :with_debug_info is set
|
350
|
+
if opts[:with_debug_info]
|
351
|
+
iv = {}
|
352
|
+
pe.instance_eval do
|
353
|
+
instance_variables.each {|sym|
|
354
|
+
next if IGNORE_ATTRIBUTES.include?(sym)
|
355
|
+
key = sym.to_s[1..-1] # removes first '@'
|
356
|
+
iv[key] = instance_variable_get(sym)
|
357
|
+
}
|
358
|
+
end
|
359
|
+
obj['instance_variables'] = iv
|
360
|
+
elsif ivars = opts[:ivars]
|
361
|
+
iv = {}
|
362
|
+
ivars.each {|name|
|
363
|
+
iname = "@#{name}"
|
364
|
+
iv[name] = pe.instance_variable_get(iname) if pe.instance_variable_defined?(iname)
|
365
|
+
}
|
366
|
+
obj['instance_variables'] = iv
|
367
|
+
end
|
368
|
+
|
369
|
+
obj
|
370
|
+
end
|
371
|
+
|
372
|
+
RETRY_INFO = {
|
373
|
+
'start' => '@start',
|
374
|
+
'steps' => '@steps',
|
375
|
+
'next_time' => '@next_time',
|
376
|
+
}
|
377
|
+
|
378
|
+
def get_retry_info(pe_retry)
|
379
|
+
retry_variables = {}
|
380
|
+
|
381
|
+
if pe_retry
|
382
|
+
RETRY_INFO.each_pair { |key, param|
|
383
|
+
retry_variables[key] = pe_retry.instance_variable_get(param)
|
384
|
+
}
|
385
|
+
end
|
386
|
+
|
387
|
+
retry_variables
|
388
|
+
end
|
389
|
+
|
390
|
+
def plugin_category(pe)
|
391
|
+
case pe
|
392
|
+
when Fluent::Plugin::Input
|
393
|
+
'input'.freeze
|
394
|
+
when Fluent::Plugin::Output, Fluent::Plugin::MultiOutput, Fluent::Plugin::BareOutput
|
395
|
+
'output'.freeze
|
396
|
+
when Fluent::Plugin::Filter
|
397
|
+
'filter'.freeze
|
398
|
+
else
|
399
|
+
'unknown'.freeze
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
def fluentd_opts
|
404
|
+
@fluentd_opts ||= get_fluentd_opts
|
405
|
+
end
|
406
|
+
|
407
|
+
def get_fluentd_opts
|
408
|
+
opts = {}
|
409
|
+
ObjectSpace.each_object(Fluent::Supervisor) { |obj|
|
410
|
+
opts.merge!(obj.options)
|
411
|
+
break
|
412
|
+
}
|
413
|
+
opts
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-monitor-agent-modified
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- wanfeng.hu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-14 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.14.10
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.14.10
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '11.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '11.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: flexmock
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: parallel_tests
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.15.3
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.15.3
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.7'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.7'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rr
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: timecop
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.3'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0.3'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: test-unit
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '3.2'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '3.2'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: test-unit-rr
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1.0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: oj
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '2.14'
|
152
|
+
- - "<"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '4'
|
155
|
+
type: :development
|
156
|
+
prerelease: false
|
157
|
+
version_requirements: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '2.14'
|
162
|
+
- - "<"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '4'
|
165
|
+
description: Modified version of default in_monitor_agent in fluentd. It can monitor
|
166
|
+
number of emitted records during emit_interval when tag is configured.
|
167
|
+
email:
|
168
|
+
- wanfeng.hu@ihandysoft.com
|
169
|
+
executables: []
|
170
|
+
extensions: []
|
171
|
+
extra_rdoc_files: []
|
172
|
+
files:
|
173
|
+
- ".DS_Store"
|
174
|
+
- ".gitignore"
|
175
|
+
- Gemfile
|
176
|
+
- LISENCE
|
177
|
+
- README.md
|
178
|
+
- Rakefile
|
179
|
+
- fluent-plugin-monitor-agent-modified.gemspec
|
180
|
+
- lib/.DS_Store
|
181
|
+
- lib/fluent/.DS_Store
|
182
|
+
- lib/fluent/plugin/.DS_Store
|
183
|
+
- lib/fluent/plugin/in_monitor_agent_modified.rb
|
184
|
+
- lib/fluent/version.rb
|
185
|
+
homepage: https://github.com/BlackNight95/fluent-plugin-monitor-agent-modified
|
186
|
+
licenses:
|
187
|
+
- Apache-2.0
|
188
|
+
metadata: {}
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
require_paths:
|
192
|
+
- lib
|
193
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
requirements: []
|
204
|
+
rubyforge_project:
|
205
|
+
rubygems_version: 2.5.2.3
|
206
|
+
signing_key:
|
207
|
+
specification_version: 4
|
208
|
+
summary: Outputs monitor informations for fluentd
|
209
|
+
test_files: []
|