fluent-plugin-proc-info 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: efaf9966a6c2f3bceb5ca7b958f732187ebd5f4369b5624fbc0ad3d0ce71edc6
4
+ data.tar.gz: d6542cf85574e31bf5936fe0c6275064743fcd3953e3e82ad880e604fc03445a
5
+ SHA512:
6
+ metadata.gz: a36a70eb9b32063bd40c8dd67d36cdf0737239977ab484afb4c20436ff1ef89c2b2e5b0094c2c96d196996f02e78bf6e0494e3077f84910e9382ba34b79d991b
7
+ data.tar.gz: 129792803e16237594261413a23a0450eca68445c27a213fc9dadc6970bb60282e31990dda3d5943d4821dc2ca4188a5ba0c8053c7759db0f3e6cc1c8af38174
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ # tmp files
2
+ /tmp
3
+ .byebug_history
4
+ /coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,36 @@
1
+ require:
2
+ - rubocop-rake
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
6
+ NewCops: enable
7
+
8
+ Gemspec/DevelopmentDependencies:
9
+ Enabled: false
10
+
11
+ Layout/LineLength:
12
+ Max: 100
13
+
14
+ # Metrics/AbcSize:
15
+ # Max: 40
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - fluent-plugin-proc-info.gemspec
20
+ - test/**/*.rb
21
+
22
+ Metrics/ClassLength:
23
+ Exclude:
24
+ - test/**/*.rb
25
+ - lib/fluent/plugin/in_proc_info.rb
26
+
27
+ Metrics/MethodLength:
28
+ Max: 25
29
+ Exclude:
30
+ - test/**/*.rb
31
+
32
+ Metrics/ParameterLists:
33
+ Exclude: []
34
+
35
+ Style/Documentation:
36
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,139 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-proc-info (0.1.0)
5
+ fluentd (>= 0.14.10, < 2)
6
+ procfs2 (~> 0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ base64 (0.2.0)
13
+ bigdecimal (3.1.8)
14
+ bump (0.10.0)
15
+ byebug (11.1.3)
16
+ concurrent-ruby (1.2.3)
17
+ cool.io (1.8.0)
18
+ csv (3.3.0)
19
+ docile (1.4.0)
20
+ drb (2.2.1)
21
+ dry-configurable (1.1.0)
22
+ dry-core (~> 1.0, < 2)
23
+ zeitwerk (~> 2.6)
24
+ dry-core (1.0.1)
25
+ concurrent-ruby (~> 1.0)
26
+ zeitwerk (~> 2.6)
27
+ dry-inflector (1.0.0)
28
+ dry-initializer (3.1.1)
29
+ dry-logic (1.5.0)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-core (~> 1.0, < 2)
32
+ zeitwerk (~> 2.6)
33
+ dry-schema (1.13.3)
34
+ concurrent-ruby (~> 1.0)
35
+ dry-configurable (~> 1.0, >= 1.0.1)
36
+ dry-core (~> 1.0, < 2)
37
+ dry-initializer (~> 3.0)
38
+ dry-logic (>= 1.4, < 2)
39
+ dry-types (>= 1.7, < 2)
40
+ zeitwerk (~> 2.6)
41
+ dry-types (1.7.2)
42
+ bigdecimal (~> 3.0)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-core (~> 1.0)
45
+ dry-inflector (~> 1.0)
46
+ dry-logic (~> 1.4)
47
+ zeitwerk (~> 2.6)
48
+ fluentd (1.17.0)
49
+ base64 (~> 0.2)
50
+ bundler
51
+ cool.io (>= 1.4.5, < 2.0.0)
52
+ csv (~> 3.2)
53
+ drb (~> 2.2)
54
+ http_parser.rb (>= 0.5.1, < 0.9.0)
55
+ msgpack (>= 1.3.1, < 2.0.0)
56
+ serverengine (>= 2.3.2, < 3.0.0)
57
+ sigdump (~> 0.2.5)
58
+ strptime (>= 0.2.4, < 1.0.0)
59
+ tzinfo (>= 1.0, < 3.0)
60
+ tzinfo-data (~> 1.0)
61
+ webrick (~> 1.4)
62
+ yajl-ruby (~> 1.0)
63
+ http_parser.rb (0.8.0)
64
+ json (2.7.2)
65
+ language_server-protocol (3.17.0.3)
66
+ msgpack (1.7.2)
67
+ parallel (1.24.0)
68
+ parser (3.3.1.0)
69
+ ast (~> 2.4.1)
70
+ racc
71
+ power_assert (2.0.3)
72
+ procfs2 (0.1.0)
73
+ racc (1.7.3)
74
+ rainbow (3.1.1)
75
+ rake (13.2.1)
76
+ reek (6.3.0)
77
+ dry-schema (~> 1.13.0)
78
+ parser (~> 3.3.0)
79
+ rainbow (>= 2.0, < 4.0)
80
+ rexml (~> 3.1)
81
+ regexp_parser (2.9.0)
82
+ rexml (3.2.6)
83
+ rubocop (1.63.5)
84
+ json (~> 2.3)
85
+ language_server-protocol (>= 3.17.0)
86
+ parallel (~> 1.10)
87
+ parser (>= 3.3.0.2)
88
+ rainbow (>= 2.2.2, < 4.0)
89
+ regexp_parser (>= 1.8, < 3.0)
90
+ rexml (>= 3.2.5, < 4.0)
91
+ rubocop-ast (>= 1.31.1, < 2.0)
92
+ ruby-progressbar (~> 1.7)
93
+ unicode-display_width (>= 2.4.0, < 3.0)
94
+ rubocop-ast (1.31.3)
95
+ parser (>= 3.3.1.0)
96
+ rubocop-rake (0.6.0)
97
+ rubocop (~> 1.0)
98
+ ruby-progressbar (1.13.0)
99
+ serverengine (2.3.2)
100
+ sigdump (~> 0.2.2)
101
+ sigdump (0.2.5)
102
+ simplecov (0.22.0)
103
+ docile (~> 1.1)
104
+ simplecov-html (~> 0.11)
105
+ simplecov_json_formatter (~> 0.1)
106
+ simplecov-html (0.12.3)
107
+ simplecov_json_formatter (0.1.4)
108
+ strptime (0.2.5)
109
+ test-unit (3.6.2)
110
+ power_assert
111
+ timecop (0.9.8)
112
+ tzinfo (2.0.6)
113
+ concurrent-ruby (~> 1.0)
114
+ tzinfo-data (1.2024.1)
115
+ tzinfo (>= 1.0.0)
116
+ unicode-display_width (2.5.0)
117
+ webrick (1.8.1)
118
+ yajl-ruby (1.4.3)
119
+ zeitwerk (2.6.13)
120
+
121
+ PLATFORMS
122
+ ruby
123
+ x86_64-linux
124
+
125
+ DEPENDENCIES
126
+ bump (~> 0.10.0)
127
+ bundler (~> 2.5.9)
128
+ byebug (~> 11.1, >= 11.1.3)
129
+ fluent-plugin-proc-info!
130
+ rake (~> 13.2.1)
131
+ reek (~> 6.1, >= 6.1.4)
132
+ rubocop (~> 1.56)
133
+ rubocop-rake (~> 0.6.0)
134
+ simplecov (~> 0.22.0)
135
+ test-unit (~> 3.6.2)
136
+ timecop (~> 0.9.6)
137
+
138
+ BUNDLED WITH
139
+ 2.5.9
data/LICENSE 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 [yyyy] [name of copyright owner]
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,42 @@
1
+ # fluent-plugin-proc-info
2
+
3
+ [Fluentd](https://fluentd.org/) plugin to generate proc info for a given process.
4
+
5
+
6
+ ## plugins
7
+
8
+ ### in - proc_info
9
+
10
+ #### config
11
+
12
+ | setting | type | default | description |
13
+ |---------|------|---------|-------------|
14
+ | | | | |
15
+
16
+ #### example
17
+
18
+ Configuration example:
19
+
20
+ ``` text
21
+ <source>
22
+ @type ...
23
+ </source>
24
+ ```
25
+
26
+
27
+ ## installation
28
+
29
+ Manual install, by executing:
30
+
31
+ $ gem install fluent-plugin-proc-info
32
+
33
+ Add to Gemfile with:
34
+
35
+ $ bundle add fluent-plugin-proc-info
36
+
37
+
38
+ ## Copyright
39
+
40
+ * Copyright(c) 2024- Thomas Tych
41
+ * License
42
+ * Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rake/testtask'
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs.push('lib', 'test')
9
+ t.test_files = FileList['test/**/test_*.rb', 'test/**/*_test.rb',]
10
+ t.verbose = true
11
+ t.warning = true
12
+ end
13
+
14
+ require 'rubocop/rake_task'
15
+ RuboCop::RakeTask.new
16
+
17
+ require 'bump/tasks'
18
+
19
+ task default: %i[test rubocop]
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fluent-plugin-proc-info'
8
+ spec.version = '0.1.0'
9
+ spec.authors = ['Thomas Tych']
10
+ spec.email = ['thomas.tych@gmail.com']
11
+
12
+ spec.summary = 'fluentd plugin to access proc info for a given process.'
13
+ spec.homepage = 'https://gitlab.com/ttych/fluent-plugin-proc-info'
14
+ spec.license = 'Apache-2.0'
15
+
16
+ spec.required_ruby_version = '>= 2.7.0'
17
+
18
+ spec.metadata['rubygems_mfa_required'] = 'true'
19
+
20
+ _, files = `git ls-files -z`.split("\x0").partition do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ spec.files = files
24
+ spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bump', '~> 0.10.0'
28
+ spec.add_development_dependency 'bundler', '~> 2.5.9'
29
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
30
+ spec.add_development_dependency 'rake', '~> 13.2.1'
31
+ spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.4'
32
+ spec.add_development_dependency 'rubocop', '~> 1.56'
33
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
34
+ spec.add_development_dependency 'simplecov', '~> 0.22.0'
35
+ spec.add_development_dependency 'test-unit', '~> 3.6.2'
36
+ spec.add_development_dependency 'timecop', '~> 0.9.6'
37
+
38
+ spec.add_runtime_dependency 'fluentd', ['>= 0.14.10', '< 2']
39
+ spec.add_runtime_dependency 'procfs2', '~> 0.1'
40
+ end
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2024- Thomas Tych
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'fluent/plugin/input'
19
+
20
+ require_relative 'proc_info'
21
+
22
+ module Fluent
23
+ module Plugin
24
+ class ProcInfoInput < Fluent::Plugin::Input
25
+ NAME = 'proc_info'
26
+
27
+ DEFAULT_TAG = NAME
28
+ DEFAULT_INTERVAL = 60
29
+ DEFAULT_PROBES = [].freeze
30
+ DEFAULT_TIMESTAMP_KEY = 'timestamp'
31
+ DEFAULT_TIMESTAMP_FORMAT = :iso
32
+
33
+ Fluent::Plugin.register_input(NAME, self)
34
+
35
+ helpers :event_emitter, :timer
36
+
37
+ desc 'tag to emit events on'
38
+ config_param :tag, :string, default: DEFAULT_TAG
39
+
40
+ desc 'interval for probe execution'
41
+ config_param :interval, :time, default: DEFAULT_INTERVAL
42
+
43
+ config_section :process, param_name: :processes, multi: true do
44
+ desc 'from pid'
45
+ config_param :pid, :string, default: nil
46
+ desc 'from pid file content'
47
+ config_param :pid_file, :string, default: nil
48
+ end
49
+
50
+ desc 'probes to collect'
51
+ config_param :probes, :array, default: DEFAULT_PROBES, value_type: :string
52
+
53
+ desc 'timestamp key'
54
+ config_param :timestamp_key, :string, default: DEFAULT_TIMESTAMP_KEY
55
+ desc 'timestamp format'
56
+ config_param :timestamp_format, :enum, list: %i[iso epochmillis],
57
+ default: DEFAULT_TIMESTAMP_FORMAT
58
+
59
+ desc 'data field prefix'
60
+ config_param :event_prefix, :string, default: ''
61
+ desc 'metadata field prefix'
62
+ config_param :metadata_prefix, :string, default: ''
63
+
64
+ attr_reader :info_processes, :eventer
65
+
66
+ def configure(conf)
67
+ super
68
+
69
+ raise Fluent::ConfigError, "#{NAME}: `tag` must be specified" if tag.nil? || tag.empty?
70
+ raise Fluent::ConfigError, "#{NAME}: `interval` must >= 1" if interval < 1
71
+ raise Fluent::ConfigError, "#{NAME}: `probes` must not be empty" if probes.empty?
72
+
73
+ configure_eventer
74
+ configure_processes
75
+ end
76
+
77
+ def configure_eventer
78
+ if timestamp_key.empty?
79
+ raise Fluent::ConfigError,
80
+ "#{NAME}: `timestamp_key` must not be empty"
81
+ end
82
+
83
+ @eventer = ProcInfo::Eventer.new(
84
+ timestamp_key: timestamp_key,
85
+ timestamp_format: timestamp_format,
86
+ event_prefix: event_prefix,
87
+ metadata_prefix: metadata_prefix
88
+ )
89
+ end
90
+
91
+ def configure_processes
92
+ raise Fluent::ConfigError, "#{NAME}: no `process` definition found" if processes.empty?
93
+
94
+ @info_processes = processes.map do |process|
95
+ ProcInfo::Process.new(pid: process.pid, pid_file: process.pid_file, eventer: eventer,
96
+ logger: log)
97
+ rescue StandardError => e
98
+ raise Fluent::ConfigError, "#{NAME}: #{e}"
99
+ end
100
+ end
101
+
102
+ def multi_workers_ready?
103
+ true
104
+ end
105
+
106
+ def start
107
+ super
108
+
109
+ timer_execute(:run_first, 1, repeat: false, &method(:run)) if interval > 60
110
+ timer_execute(:run_interval, interval, repeat: true, &method(:run))
111
+ end
112
+
113
+ def run
114
+ info_processes.each do |info_process|
115
+ events = info_process.probe(probes: probes)
116
+ emit_events(events)
117
+ end
118
+ end
119
+
120
+ def emit_events(events)
121
+ return if events.nil? || events.empty?
122
+
123
+ time = Fluent::Engine.now
124
+ mes = MultiEventStream.new
125
+ events.each do |event|
126
+ event = reformat_event(event)
127
+ mes.add(time, event)
128
+ end
129
+ router.emit_stream(tag, mes)
130
+ end
131
+
132
+ def reformat_event(event)
133
+ # FIXME
134
+ # - prefix data
135
+ # - prefix metadata
136
+ # - timestamp
137
+ event
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'procfs2'
4
+
5
+ module Fluent
6
+ module Plugin
7
+ module ProcInfo
8
+ class Eventer
9
+ attr_reader :timestamp_key, :timestamp_format, :event_prefix, :metadata_prefix
10
+
11
+ def initialize(timestamp_key:,
12
+ timestamp_format:,
13
+ event_prefix:,
14
+ metadata_prefix:)
15
+ @timestamp_key = timestamp_key
16
+ @timestamp_format = timestamp_format
17
+ @event_prefix = event_prefix
18
+ @metadata_prefix = metadata_prefix
19
+ end
20
+
21
+ def generate_event(name:, value:, metadata: {})
22
+ base.update({
23
+ "#{event_prefix}name" => name,
24
+ "#{event_prefix}value" => value
25
+ })
26
+ .update(metadata.transform_keys { |k| "#{metadata_prefix}#{k}" })
27
+ end
28
+
29
+ private
30
+
31
+ def base
32
+ { timestamp_key.to_s => timestamp }
33
+ end
34
+
35
+ def timestamp
36
+ send("timestamp_#{timestamp_format}")
37
+ end
38
+
39
+ def timestamp_epochmillis
40
+ (Time.now.utc.to_f * 1000).to_i
41
+ end
42
+
43
+ def timestamp_iso
44
+ Time.now.utc.iso8601(3)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'procfs2'
4
+
5
+ module Fluent
6
+ module Plugin
7
+ module ProcInfo
8
+ class Process
9
+ attr_reader :eventer, :logger
10
+
11
+ def initialize(pid: nil, pid_file: nil, eventer: nil, logger: nil)
12
+ @pid = pid
13
+ @pid_file = pid_file
14
+ @eventer = eventer
15
+ @logger = logger
16
+
17
+ validate_pid
18
+ end
19
+
20
+ def probe(probes: [])
21
+ events = []
22
+
23
+ probes.each do |probe|
24
+ events += send("probe_#{probe}")
25
+ rescue StandardError => e
26
+ log.error("Process probe error with probe `#{probe}`: #{e}")
27
+ end
28
+
29
+ events
30
+ end
31
+
32
+ def probe_net
33
+ probe_net_tcp + probe_net_udp
34
+ end
35
+
36
+ def probe_net_tcp
37
+ net_inodes = proc.pid(pid).fd.select { |fd| fd.type == 'socket' }.map(&:inode)
38
+ tcp_sockets = net_inodes.map { |net_inode| proc.net.tcp.by_inode(net_inode) }.compact
39
+
40
+ incomings = {}
41
+ outgoings = {}
42
+ remainings = []
43
+
44
+ local_port_groups = tcp_sockets.group_by(&:local_port)
45
+ local_port_groups.each_value do |sockets|
46
+ next if sockets.empty?
47
+
48
+ if sockets.size == 1 && sockets.first.state_str != 'LISTEN'
49
+ remainings << sockets.first
50
+ next
51
+ end
52
+ incomings.update(sockets.group_by { |socket| [socket.local_port, socket.state_str] })
53
+ end
54
+
55
+ r_tcp_sockets = remainings
56
+ remainings = []
57
+ remote_port_groups = r_tcp_sockets.group_by(&:remote_port)
58
+ remote_port_groups.each_value do |sockets|
59
+ next if sockets.empty?
60
+
61
+ if sockets.size == 1
62
+ remainings << sockets.first
63
+ next
64
+ end
65
+ outgoings.update(sockets.group_by { |socket| [socket.remote_port, socket.state_str] })
66
+ end
67
+
68
+ remainings = remainings.group_by(&:state_str)
69
+
70
+ events = incomings.map do |group_attrs, sockets|
71
+ eventer.generate_event(
72
+ name: 'connection_count',
73
+ value: sockets.size,
74
+ metadata: {
75
+ protocol: 'tcp',
76
+ direction: 'in',
77
+ port: group_attrs[0],
78
+ state: group_attrs[1]
79
+ }
80
+ )
81
+ end
82
+ outgoings.each do |group_attrs, sockets|
83
+ events << eventer.generate_event(
84
+ name: 'connection_count',
85
+ value: sockets.size,
86
+ metadata: {
87
+ protocol: 'tcp',
88
+ direction: 'out',
89
+ port: group_attrs[0],
90
+ state: group_attrs[1]
91
+ }
92
+ )
93
+ end
94
+ remainings.each do |state, sockets|
95
+ events << eventer.generate_event(
96
+ name: 'connection_count',
97
+ value: sockets.size,
98
+ metadata: {
99
+ protocol: 'tcp',
100
+ direction: 'unknown',
101
+ port: nil,
102
+ state: state
103
+ }
104
+ )
105
+ end
106
+
107
+ events
108
+ end
109
+
110
+ def probe_net_udp
111
+ []
112
+ end
113
+
114
+ private
115
+
116
+ def validate_pid
117
+ return if (@pid && !@pid_file) || (!@pid && @pid_file)
118
+
119
+ raise 'process definition should have pid XOR pid_file entry'
120
+ end
121
+
122
+ def pid
123
+ return @pid if @pid
124
+
125
+ begin
126
+ return File.read(@pid_file).strip
127
+ rescue StandardError => e
128
+ log&.warn("error while loading pid file #{@pid_file}: #{e}")
129
+ end
130
+
131
+ nil
132
+ end
133
+
134
+ def log
135
+ logger
136
+ end
137
+
138
+ def proc
139
+ Procfs2.proc
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'proc_info/eventer'
4
+ require_relative 'proc_info/process'
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-proc-info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Tych
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.9
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 11.1.3
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '11.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 11.1.3
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 13.2.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 13.2.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: reek
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '6.1'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 6.1.4
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '6.1'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 6.1.4
95
+ - !ruby/object:Gem::Dependency
96
+ name: rubocop
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.56'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.56'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rubocop-rake
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 0.6.0
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 0.6.0
123
+ - !ruby/object:Gem::Dependency
124
+ name: simplecov
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.22.0
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 0.22.0
137
+ - !ruby/object:Gem::Dependency
138
+ name: test-unit
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: 3.6.2
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: 3.6.2
151
+ - !ruby/object:Gem::Dependency
152
+ name: timecop
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: 0.9.6
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: 0.9.6
165
+ - !ruby/object:Gem::Dependency
166
+ name: fluentd
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: 0.14.10
172
+ - - "<"
173
+ - !ruby/object:Gem::Version
174
+ version: '2'
175
+ type: :runtime
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: 0.14.10
182
+ - - "<"
183
+ - !ruby/object:Gem::Version
184
+ version: '2'
185
+ - !ruby/object:Gem::Dependency
186
+ name: procfs2
187
+ requirement: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - "~>"
190
+ - !ruby/object:Gem::Version
191
+ version: '0.1'
192
+ type: :runtime
193
+ prerelease: false
194
+ version_requirements: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - "~>"
197
+ - !ruby/object:Gem::Version
198
+ version: '0.1'
199
+ description:
200
+ email:
201
+ - thomas.tych@gmail.com
202
+ executables: []
203
+ extensions: []
204
+ extra_rdoc_files: []
205
+ files:
206
+ - ".gitignore"
207
+ - ".rubocop.yml"
208
+ - Gemfile
209
+ - Gemfile.lock
210
+ - LICENSE
211
+ - README.md
212
+ - Rakefile
213
+ - fluent-plugin-proc-info.gemspec
214
+ - lib/fluent/plugin/in_proc_info.rb
215
+ - lib/fluent/plugin/proc_info.rb
216
+ - lib/fluent/plugin/proc_info/eventer.rb
217
+ - lib/fluent/plugin/proc_info/process.rb
218
+ homepage: https://gitlab.com/ttych/fluent-plugin-proc-info
219
+ licenses:
220
+ - Apache-2.0
221
+ metadata:
222
+ rubygems_mfa_required: 'true'
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: 2.7.0
232
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ requirements: []
238
+ rubygems_version: 3.5.9
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: fluentd plugin to access proc info for a given process.
242
+ test_files: []