fluentd 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +15 -6
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/CHANGELOG.md +29 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -0
- data/Rakefile +6 -1
- data/appveyor.yml +9 -10
- data/lib/fluent/command/fluentd.rb +4 -0
- data/lib/fluent/config/literal_parser.rb +2 -2
- data/lib/fluent/plugin/base.rb +1 -0
- data/lib/fluent/plugin/buffer.rb +22 -0
- data/lib/fluent/plugin/in_forward.rb +2 -2
- data/lib/fluent/plugin/in_monitor_agent.rb +90 -131
- data/lib/fluent/plugin/out_forward.rb +4 -0
- data/lib/fluent/plugin/output.rb +31 -1
- data/lib/fluent/plugin/parser_none.rb +1 -2
- data/lib/fluent/plugin_helper.rb +1 -0
- data/lib/fluent/plugin_helper/cert_option.rb +1 -1
- data/lib/fluent/plugin_helper/http_server.rb +75 -0
- data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
- data/lib/fluent/plugin_helper/http_server/compat/server.rb +81 -0
- data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
- data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
- data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
- data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
- data/lib/fluent/plugin_helper/http_server/server.rb +87 -0
- data/lib/fluent/plugin_helper/socket.rb +8 -2
- data/lib/fluent/supervisor.rb +5 -2
- data/lib/fluent/time.rb +13 -0
- data/lib/fluent/version.rb +1 -1
- data/test/command/test_fluentd.rb +36 -2
- data/test/helper.rb +1 -0
- data/test/helpers/fuzzy_assert.rb +89 -0
- data/test/plugin/test_buf_file.rb +1 -1
- data/test/plugin/test_in_http.rb +2 -5
- data/test/plugin/test_in_monitor_agent.rb +118 -17
- data/test/plugin/test_in_udp.rb +0 -2
- data/test/plugin/test_out_file.rb +15 -12
- data/test/plugin/test_out_forward.rb +18 -0
- data/test/plugin/test_out_secondary_file.rb +6 -4
- data/test/plugin/test_output_as_buffered.rb +4 -0
- data/test/plugin/test_output_as_buffered_retries.rb +0 -2
- data/test/plugin/test_output_as_buffered_secondary.rb +0 -3
- data/test/plugin_helper/data/cert/cert-key.pem +27 -0
- data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
- data/test/plugin_helper/data/cert/cert.pem +19 -0
- data/test/plugin_helper/http_server/test_app.rb +65 -0
- data/test/plugin_helper/http_server/test_route.rb +32 -0
- data/test/plugin_helper/test_cert_option.rb +16 -0
- data/test/plugin_helper/test_http_server_helper.rb +203 -0
- data/test/plugin_helper/test_server.rb +1 -7
- data/test/test_event_time.rb +13 -0
- data/test/test_log.rb +8 -6
- data/test/test_supervisor.rb +3 -0
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d97f061ed5f540026a4cae384b2508ee503be4dcb0ef836d37e118a541477df
|
4
|
+
data.tar.gz: 82edeaa9350871f8ba1b38d966cfc331f56c5ba97464c3dd14fb2bf7005a1bb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7966763ba1215bde1a571f500dedaf5a100b6e72f14fb8b8121e09ca7d3fe697e4c6910b3dd7f844bd3d86484f0ea656997baff81fd9332aab94a898ff2e74d7
|
7
|
+
data.tar.gz: be65ac015fc43ac71d52ad3a2bb628e904a285918588b31102ecdf51e84af689ef77007028b30c72a9ecc25aa01e50a88091f136829396bf7cacaa608312b591
|
data/.github/ISSUE_TEMPLATE.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
Check [CONTRIBUTING guideline](https://github.com/fluent/fluentd/blob/master/CONTRIBUTING.md) first and here is the list to help us investigate the problem.
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
**Got a question or problem?**
|
4
|
+
|
5
|
+
RESOURCES of [Official site](https://www.fluentd.org/) and [Fluentd documentation](https://docs.fluentd.org/) may help you.
|
6
|
+
|
7
|
+
If you have further questions about Fluentd and plugins, please direct these to [Mailing List](https://groups.google.com/forum/#!forum/fluentd).
|
8
|
+
Don't use Github issue for asking questions. Here are examples:
|
9
|
+
|
10
|
+
- I installed xxx plugin but it doesn't work. Why?
|
11
|
+
- Fluentd starts but logs are not sent to xxx. Am I wrong?
|
12
|
+
- I want to do xxx. How to realize it with plugins?
|
13
|
+
|
14
|
+
We may close such questions to keep clear repository for developers and users.
|
15
|
+
Github issue is mainly for submitting a bug report or feature request. See below.
|
16
|
+
|
17
|
+
If you can't judge your case is a bug or not, use mailing list or slack first.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
---
|
2
|
+
name: Bug Report
|
3
|
+
about: Create a report to help us improve. If you have questions about Fluentd and plugins, please direct these to https://groups.google.com/forum/#!forum/fluentd
|
4
|
+
labels: 'bug'
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
Check [CONTRIBUTING guideline](https://github.com/fluent/fluentd/blob/master/CONTRIBUTING.md) first and here is the list to help us investigate the problem.
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
<!-- A clear and concise description of what the bug is. -->
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
<!-- Steps to reproduce the behavior: -->
|
15
|
+
|
16
|
+
**Expected behavior**
|
17
|
+
<!-- A clear and concise description of what you expected to happen. -->
|
18
|
+
|
19
|
+
**Your Environment**
|
20
|
+
|
21
|
+
- Fluentd or td-agent version: `fluentd --version` or `td-agent --version`
|
22
|
+
- Operating system: `cat /etc/os-release`
|
23
|
+
- Kernel version: `uname -r`
|
24
|
+
|
25
|
+
**Your Configuration**
|
26
|
+
|
27
|
+
```
|
28
|
+
<!-- Write your configuration here -->
|
29
|
+
```
|
30
|
+
|
31
|
+
**Your Error Log**
|
32
|
+
|
33
|
+
```
|
34
|
+
<!-- Write your **ALL** error log here -->
|
35
|
+
```
|
36
|
+
|
37
|
+
**Additional context**
|
38
|
+
|
39
|
+
<!-- Add any other context about the problem here. -->
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
Check [CONTRIBUTING guideline](https://github.com/fluent/fluentd/blob/master/CONTRIBUTING.md) first and here is the list to help us investigate the problem.
|
8
|
+
|
9
|
+
**Is your feature request related to a problem? Please describe.**
|
10
|
+
|
11
|
+
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
|
15
|
+
<!-- A clear and concise description of what you want to happen. -->
|
16
|
+
|
17
|
+
**Describe alternatives you've considered**
|
18
|
+
|
19
|
+
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
20
|
+
|
21
|
+
**Additional context**
|
22
|
+
|
23
|
+
<!-- Add any other context or screenshots about the feature request here. -->
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
# v1.6
|
2
|
+
|
3
|
+
## Release v1.6.0 - 2019/07/01
|
4
|
+
|
5
|
+
### New feature
|
6
|
+
|
7
|
+
* plugin: Add http_server helper and in_monitor_agent use it
|
8
|
+
https://github.com/fluent/fluentd/pull/2447
|
9
|
+
|
10
|
+
### Enhancement
|
11
|
+
|
12
|
+
* in_monitor_agent: Add more metrics for buffer/output
|
13
|
+
https://github.com/fluent/fluentd/pull/2450
|
14
|
+
* time/plugin: Add `EventTime#to_time` method for fast conversion
|
15
|
+
https://github.com/fluent/fluentd/pull/2469
|
16
|
+
* socket helper/out_forward: Add connect_timeout parameter
|
17
|
+
https://github.com/fluent/fluentd/pull/2467
|
18
|
+
* command: Add `--conf-encoding` option
|
19
|
+
https://github.com/fluent/fluentd/pull/2453
|
20
|
+
* parser_none: Small performance optimization
|
21
|
+
https://github.com/fluent/fluentd/pull/2455
|
22
|
+
|
23
|
+
### Bug fixes
|
24
|
+
|
25
|
+
* cert: Fix cert match pattern
|
26
|
+
https://github.com/fluent/fluentd/pull/2466
|
27
|
+
* output: Fix forget to increment rollback count
|
28
|
+
https://github.com/fluent/fluentd/pull/2462
|
29
|
+
|
1
30
|
# v1.5
|
2
31
|
|
3
32
|
## Release v1.5.2 - 2019/06/13
|
data/CONTRIBUTING.md
CHANGED
@@ -24,7 +24,7 @@ If you find a bug of Fluentd or a mistake in the documentation, you can help us
|
|
24
24
|
submitting an issue to Fluentd. Even better you can submit a Pull Request with a fix.
|
25
25
|
|
26
26
|
* **Fluentd**: Use [fluentd](https://github.com/fluent/fluentd) repository. Fill issue template.
|
27
|
-
* **Documentation**: Use [fluentd-docs](https://github.com/fluent/fluentd-docs) repository.
|
27
|
+
* **Documentation**: Use [fluentd-docs](https://github.com/fluent/fluentd-docs-gitbook) repository.
|
28
28
|
|
29
29
|
If you find a bug of 3rd party plugins, please submit an issue to each plugin repository.
|
30
30
|
And use [omnibus-td-agent](https://github.com/treasure-data/omnibus-td-agent) repository for td-agent related issues.
|
data/Gemfile
CHANGED
@@ -2,6 +2,11 @@ source 'https://rubygems.org/'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
# https://github.com/socketry/async-io/blob/v1.23.1/async-io.gemspec#L21
|
6
|
+
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('2.3.0')
|
7
|
+
gem 'async-http', '~> 0.42'
|
8
|
+
end
|
9
|
+
|
5
10
|
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
|
6
11
|
if File.exist?(local_gemfile)
|
7
12
|
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
|
data/Rakefile
CHANGED
@@ -34,7 +34,12 @@ Rake::TestTask.new(:base_test) do |t|
|
|
34
34
|
t.test_files = if ENV["WIN_RAPID"]
|
35
35
|
["test/test_event.rb", "test/test_supervisor.rb", "test/plugin_helper/test_event_loop.rb"]
|
36
36
|
else
|
37
|
-
Dir["test/**/test_*.rb"].sort
|
37
|
+
tests = Dir["test/**/test_*.rb"].sort
|
38
|
+
if Process.uid.zero?
|
39
|
+
puts "test_file_util.rb for non-root user env. Disable this test on root environment"
|
40
|
+
tests.delete("test/plugin/test_file_util.rb")
|
41
|
+
end
|
42
|
+
tests
|
38
43
|
end
|
39
44
|
t.verbose = true
|
40
45
|
t.warning = true
|
data/appveyor.yml
CHANGED
@@ -5,10 +5,11 @@ version: '{build}'
|
|
5
5
|
|
6
6
|
install:
|
7
7
|
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
8
|
-
- "%devkit%\\devkitvars.bat"
|
8
|
+
- IF %ridk%==0 "%devkit%\\devkitvars.bat"
|
9
9
|
- ruby --version
|
10
10
|
- gem --version
|
11
|
-
- bundle install
|
11
|
+
- IF %ridk%==1 ridk.cmd exec bundle install
|
12
|
+
- IF %ridk%==0 bundle install
|
12
13
|
build: off
|
13
14
|
test_script:
|
14
15
|
- bundle exec rake test
|
@@ -17,22 +18,20 @@ test_script:
|
|
17
18
|
branches:
|
18
19
|
only:
|
19
20
|
- master
|
20
|
-
- v0.10
|
21
|
-
- v0.12
|
22
|
-
- v0.14
|
23
21
|
|
24
22
|
# https://www.appveyor.com/docs/installed-software/#ruby
|
25
23
|
environment:
|
26
24
|
matrix:
|
27
25
|
- ruby_version: "23-x64"
|
28
26
|
devkit: C:\Ruby23-x64\DevKit
|
27
|
+
ridk: 0
|
29
28
|
- ruby_version: "23"
|
30
29
|
devkit: C:\Ruby23\DevKit
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
ridk: 0
|
31
|
+
- ruby_version: "24-x64"
|
32
|
+
ridk: 1
|
33
|
+
- ruby_version: "24"
|
34
|
+
ridk: 1
|
36
35
|
matrix:
|
37
36
|
allow_failures:
|
38
37
|
- ruby_version: "21"
|
@@ -155,6 +155,10 @@ op.on('-G', '--gem-path GEM_INSTALL_PATH', "Gemfile install path (default: $(dir
|
|
155
155
|
opts[:gem_install_path] = s
|
156
156
|
}
|
157
157
|
|
158
|
+
op.on('--conf-encoding ENCODING', "specify configuration file encoding") { |s|
|
159
|
+
opts[:conf_encoding] = s
|
160
|
+
}
|
161
|
+
|
158
162
|
if Fluent.windows?
|
159
163
|
require 'windows/library'
|
160
164
|
include Windows::Library
|
@@ -215,7 +215,7 @@ EOM
|
|
215
215
|
parsed = nil
|
216
216
|
begin
|
217
217
|
parsed = JSON.parse(buffer + line_buffer.rstrip.sub(/,$/, '') + (is_array ? "]" : "}"))
|
218
|
-
rescue JSON::ParserError
|
218
|
+
rescue JSON::ParserError
|
219
219
|
# This '#' is in json string literals
|
220
220
|
end
|
221
221
|
|
@@ -243,7 +243,7 @@ EOM
|
|
243
243
|
line_buffer << char
|
244
244
|
begin
|
245
245
|
result = JSON.parse(buffer + line_buffer)
|
246
|
-
rescue JSON::ParserError
|
246
|
+
rescue JSON::ParserError
|
247
247
|
# Incomplete json string yet
|
248
248
|
end
|
249
249
|
end
|
data/lib/fluent/plugin/base.rb
CHANGED
data/lib/fluent/plugin/buffer.rb
CHANGED
@@ -740,6 +740,28 @@ module Fluent
|
|
740
740
|
enqueue_chunk(metadata) if enqueue_chunk_before_retry
|
741
741
|
retry
|
742
742
|
end
|
743
|
+
|
744
|
+
def statistics
|
745
|
+
buffer_space = 1.0 - ((@stage_size + @queue_size * 1.0) / @total_limit_size).round
|
746
|
+
stats = {
|
747
|
+
'stage_length' => @stage.size,
|
748
|
+
'stage_byte_size' => @stage_size,
|
749
|
+
'queue_length' => @queue.size,
|
750
|
+
'queue_byte_size' => @queue_size,
|
751
|
+
'available_buffer_space_ratios' => buffer_space * 100,
|
752
|
+
'total_queued_size' => @stage_size + @queue_size,
|
753
|
+
}
|
754
|
+
|
755
|
+
if (m = timekeys.min)
|
756
|
+
stats['oldest_timekey'] = m
|
757
|
+
end
|
758
|
+
|
759
|
+
if (m = timekeys.max)
|
760
|
+
stats['newest_timekey'] = m
|
761
|
+
end
|
762
|
+
|
763
|
+
{ 'buffer' => stats }
|
764
|
+
end
|
743
765
|
end
|
744
766
|
end
|
745
767
|
end
|
@@ -135,13 +135,13 @@ module Fluent::Plugin
|
|
135
135
|
if client.host
|
136
136
|
begin
|
137
137
|
source = IPSocket.getaddress(client.host)
|
138
|
-
rescue SocketError
|
138
|
+
rescue SocketError
|
139
139
|
raise Fluent::ConfigError, "host '#{client.host}' cannot be resolved"
|
140
140
|
end
|
141
141
|
end
|
142
142
|
source_addr = begin
|
143
143
|
IPAddr.new(source || client.network)
|
144
|
-
rescue ArgumentError
|
144
|
+
rescue ArgumentError
|
145
145
|
raise Fluent::ConfigError, "network '#{client.network}' address format is invalid"
|
146
146
|
end
|
147
147
|
@nodes.push({
|
@@ -28,7 +28,7 @@ module Fluent::Plugin
|
|
28
28
|
class MonitorAgentInput < Input
|
29
29
|
Fluent::Plugin.register_input('monitor_agent', self)
|
30
30
|
|
31
|
-
helpers :timer, :thread
|
31
|
+
helpers :timer, :thread, :http_server
|
32
32
|
|
33
33
|
desc 'The address to bind to.'
|
34
34
|
config_param :bind, :string, default: '0.0.0.0'
|
@@ -43,35 +43,83 @@ module Fluent::Plugin
|
|
43
43
|
desc 'Determine whether to include the retry information.'
|
44
44
|
config_param :include_retry, :bool, default: true
|
45
45
|
|
46
|
-
class
|
47
|
-
def initialize(
|
46
|
+
class APIHandler
|
47
|
+
def initialize(agent)
|
48
48
|
@agent = agent
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
53
|
-
code, header, body = process(req)
|
54
|
-
rescue
|
55
|
-
code, header, body = render_json_error(500, {
|
56
|
-
'message '=> 'Internal Server Error',
|
57
|
-
'error' => "#{$!}",
|
58
|
-
'backgrace'=> $!.backtrace,
|
59
|
-
})
|
60
|
-
end
|
51
|
+
def plugins_ltsv(req)
|
52
|
+
list = build_object(build_option(req))
|
61
53
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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)
|
68
88
|
end
|
69
89
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
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"
|
73
117
|
end
|
74
118
|
|
119
|
+
[code, { 'Content-Type' => 'text/plain' }, text]
|
120
|
+
end
|
121
|
+
|
122
|
+
def build_object(opts)
|
75
123
|
qs = opts[:query]
|
76
124
|
if tag = qs['tag'.freeze].first
|
77
125
|
# ?tag= to search an output plugin by match pattern
|
@@ -98,30 +146,11 @@ module Fluent::Plugin
|
|
98
146
|
list
|
99
147
|
end
|
100
148
|
|
101
|
-
def render_json(obj, opts={})
|
102
|
-
render_json_error(200, obj, opts)
|
103
|
-
end
|
104
|
-
|
105
|
-
def render_json_error(code, obj, opts={})
|
106
|
-
if opts[:pretty_json]
|
107
|
-
js = JSON.pretty_generate(obj)
|
108
|
-
else
|
109
|
-
js = obj.to_json
|
110
|
-
end
|
111
|
-
[code, {'Content-Type'=>'application/json'}, js]
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
|
116
149
|
def build_option(req)
|
117
150
|
qs = Hash.new { |_, _| [] }
|
118
151
|
# parse ?=query string
|
119
152
|
if req.query_string
|
120
|
-
|
121
|
-
qs.merge!(CGI.parse(req.query_string))
|
122
|
-
rescue
|
123
|
-
return render_json_error(400, "Invalid query string")
|
124
|
-
end
|
153
|
+
qs.merge!(CGI.parse(req.query_string))
|
125
154
|
end
|
126
155
|
|
127
156
|
# if ?debug=1 is set, set :with_debug_info for get_monitor_info
|
@@ -152,74 +181,6 @@ module Fluent::Plugin
|
|
152
181
|
end
|
153
182
|
end
|
154
183
|
|
155
|
-
class LTSVMonitorServlet < MonitorServlet
|
156
|
-
def process(req)
|
157
|
-
opts = build_option(req)
|
158
|
-
list = build_object(req, opts)
|
159
|
-
return unless list
|
160
|
-
|
161
|
-
normalized = JSON.parse(list.to_json)
|
162
|
-
|
163
|
-
text = ''
|
164
|
-
|
165
|
-
normalized.map {|hash|
|
166
|
-
row = []
|
167
|
-
hash.each_pair {|k,v|
|
168
|
-
unless v.is_a?(Hash) || v.is_a?(Array)
|
169
|
-
row << "#{k}:#{v}"
|
170
|
-
end
|
171
|
-
}
|
172
|
-
text << row.join("\t") << "\n"
|
173
|
-
}
|
174
|
-
|
175
|
-
[200, {'Content-Type'=>'text/plain'}, text]
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
class JSONMonitorServlet < MonitorServlet
|
180
|
-
def process(req)
|
181
|
-
opts = build_option(req)
|
182
|
-
list = build_object(req, opts)
|
183
|
-
return unless list
|
184
|
-
|
185
|
-
render_json({
|
186
|
-
'plugins' => list
|
187
|
-
}, opts)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
class ConfigMonitorServlet < MonitorServlet
|
192
|
-
def build_object(req, _opt)
|
193
|
-
{
|
194
|
-
'pid' => Process.pid,
|
195
|
-
'ppid' => Process.ppid
|
196
|
-
}.merge(@agent.fluentd_opts)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
class LTSVConfigMonitorServlet < ConfigMonitorServlet
|
201
|
-
def process(req)
|
202
|
-
opts = build_option(req)
|
203
|
-
result = build_object(req, opts)
|
204
|
-
|
205
|
-
row = []
|
206
|
-
JSON.parse(result.to_json).each_pair { |k, v|
|
207
|
-
row << "#{k}:#{v}"
|
208
|
-
}
|
209
|
-
text = row.join("\t")
|
210
|
-
|
211
|
-
[200, {'Content-Type'=>'text/plain'}, text]
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
class JSONConfigMonitorServlet < ConfigMonitorServlet
|
216
|
-
def process(req)
|
217
|
-
opts = build_option(req)
|
218
|
-
result = build_object(req, opts)
|
219
|
-
render_json(result, opts)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
184
|
def initialize
|
224
185
|
super
|
225
186
|
|
@@ -235,23 +196,25 @@ module Fluent::Plugin
|
|
235
196
|
true
|
236
197
|
end
|
237
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
|
+
|
238
206
|
def start
|
239
207
|
super
|
240
208
|
|
241
209
|
log.debug "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins for worker#{fluentd_worker_id}"
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
}
|
248
|
-
@srv.mount('/api/plugins', LTSVMonitorServlet, self)
|
249
|
-
@srv.mount('/api/plugins.json', JSONMonitorServlet, self)
|
250
|
-
@srv.mount('/api/config', LTSVConfigMonitorServlet, self)
|
251
|
-
@srv.mount('/api/config.json', JSONConfigMonitorServlet, self)
|
252
|
-
thread_create :in_monitor_agent_servlet do
|
253
|
-
@srv.start
|
210
|
+
api_handler = APIHandler.new(self)
|
211
|
+
create_http_server(addr: @bind, port: @port, logger: log, default_app: NotFoundJson) do |serv|
|
212
|
+
serv.get('/api/plugins') { |req| api_handler.plugins_ltsv(req) }
|
213
|
+
serv.get('/api/plugins.json') { |req| api_handler.plugins_json(req) }
|
214
|
+
serv.get('/api/config') { |req| api_handler.config_ltsv(req) }
|
215
|
+
serv.get('/api/config.json') { |req| api_handler.config_json(req) }
|
254
216
|
end
|
217
|
+
|
255
218
|
if @tag
|
256
219
|
log.debug "tag parameter is specified. Emit plugins info to '#{@tag}'"
|
257
220
|
|
@@ -267,15 +230,7 @@ module Fluent::Plugin
|
|
267
230
|
end
|
268
231
|
end
|
269
232
|
|
270
|
-
|
271
|
-
if @srv
|
272
|
-
@srv.shutdown
|
273
|
-
@srv = nil
|
274
|
-
end
|
275
|
-
|
276
|
-
super
|
277
|
-
end
|
278
|
-
|
233
|
+
# They are deprecated but remain for compatibility
|
279
234
|
MONITOR_INFO = {
|
280
235
|
'output_plugin' => ->(){ is_a?(::Fluent::Plugin::Output) },
|
281
236
|
'buffer_queue_length' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.queue.size },
|
@@ -377,6 +332,10 @@ module Fluent::Plugin
|
|
377
332
|
end
|
378
333
|
}
|
379
334
|
|
335
|
+
if pe.respond_to?(:statistics)
|
336
|
+
obj.merge!(pe.statistics['output'] || {})
|
337
|
+
end
|
338
|
+
|
380
339
|
obj['retry'] = get_retry_info(pe.retry) if opts[:with_retry] and pe.instance_variable_defined?(:@retry)
|
381
340
|
|
382
341
|
# include all instance variables if :with_debug_info is set
|