fluent-tail_checker 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f6815f8029fdd412fe073361546d200a886729088305f04e87ab83f5ba32ab9
4
+ data.tar.gz: ccd920168a451237625ecb0755843fd34e2f3452ad88e449338d6fc8ecabfc9f
5
+ SHA512:
6
+ metadata.gz: f359eeef93a869b30b462e2fa60b60003ce67380ade85649f0fe615c70e0e21cbe493cbf735adf19fa7ab8538d82a5cdf052d14adb2d0a1b6cbdfb11212609a9
7
+ data.tar.gz: 6c3d3a469fd22139833c64d3f179a999c2b6cdb88dc6269f9067b6bbcefb3deaceea62f0c5ba0d792085500c1f353b480c198e0b68af9943893b3c0a966140ee
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,118 @@
1
+ # fluent-tailcheck
2
+
3
+ `fluent-tailcheck` is a command for [Fluentd](https://www.fluentd.org/).
4
+
5
+ This command checks whether [in_tail](https://docs.fluentd.org/input/tail) plugin is collecting logs properly.
6
+ For example, this command verifies whether a known critical log missing issue is occurring.
7
+
8
+ Known critical log missing issues:
9
+
10
+ * https://github.com/fluent/fluentd/issues/3614
11
+ * In case `follow_inodes false` (default setting), collection of a file may stop and continue to stop after log rotation.
12
+ * Fixed since Fluentd v1.16.3 (fluent-package v5.0.2, td-agent v4.5.2).
13
+ * https://github.com/fluent/fluentd/issues/4190
14
+ * In case `follow_inodes true`, collection of a file may stop and continue to stop after log rotation.
15
+ * Fixed since Fluentd v1.16.2 (fluent-package v5.0.0, td-agent v4.5.1).
16
+
17
+ This command allows you to check whether these issues are occurring on your Fluentd.
18
+
19
+ ## Requirements
20
+
21
+ | fluent-tailcheck | fluentd | td-agent | fluent-package |
22
+ |------------------|---------|----------|----------------|
23
+ | all versions | >= v1.0 | >= 3.1.1 | >= 5.0.0 |
24
+
25
+ ## Installation
26
+
27
+ * [fluent-package](doc/installation.md#fluent-package)
28
+ * [td-agent v4](doc/installation.md#td-agent-v4)
29
+ * [td-agent v3](doc/installation.md#td-agent-v3)
30
+ * [Your Ruby environment](doc/installation.md#your-ruby-environment)
31
+
32
+ ## Usage
33
+
34
+ ### Help
35
+
36
+ ```console
37
+ $ fluent-tailcheck --help
38
+ ```
39
+
40
+ ### Version
41
+
42
+ ```console
43
+ $ fluent-tailcheck --version
44
+ ```
45
+
46
+ ### Check pos files
47
+
48
+ You can specify a path of a pos file to check:
49
+
50
+ ```console
51
+ $ fluent-tailcheck /var/log/td-agent/pos/secure
52
+ ```
53
+
54
+ You can specify multiple paths:
55
+
56
+ ```console
57
+ $ fluent-tailcheck /var/log/td-agent/pos/secure /var/log/td-agent/pos/message
58
+ ```
59
+
60
+ You can use wildcards:
61
+
62
+ ```console
63
+ $ fluent-tailcheck /var/log/td-agent/pos/*
64
+ ```
65
+
66
+ If you use [follow_inodes](https://docs.fluentd.org/input/tail#follow_inodes), then you must specify `--follow-inodes` option.
67
+ (If you have both settings that use `follow_inodes` and those that do not, please run the command separately.)
68
+
69
+ ```console
70
+ $ fluent-tailcheck --follow-inodes /var/log/td-agent/pos/secure
71
+ ```
72
+
73
+ You can change the minimum ratio of collection of each target log file by specify `--ratio DECIMAL`.
74
+ By default (`0.5`), the command detects log files that have not been collected up to 50% of the filesize.
75
+ Please see [Collection ratio check](doc/feature.md#collection-ratio-check) for details.
76
+
77
+ ```
78
+ $ fluent-tailcheck --ratio 0.7 /var/log/td-agent/pos/secure
79
+ ```
80
+
81
+ ### Permission
82
+
83
+ `fluent-tailcheck` requires read permission to the specified pos files and the target log files.
84
+
85
+ Please use `sudo` (on Linux-like) or a terminal with administrative privileges (on Windows).
86
+
87
+ ```console
88
+ $ sudo fluent-tailcheck /var/log/td-agent/pos/secure
89
+ ```
90
+
91
+ ### Automation
92
+
93
+ It would be a good idea to run this command periodically to make sure `in_tail` works properly.
94
+
95
+ If any anomaly is detected, the command exits with an error (with a non-zero status).
96
+ You can use the exit code for the automation.
97
+
98
+ ### Result examples
99
+
100
+ * [Result examples](doc/result-examples.md)
101
+
102
+ ## Feature
103
+
104
+ * [Feature](doc/feature.md)
105
+
106
+ ## Development
107
+
108
+ * [Development](doc/development.md)
109
+
110
+ ## Contributing
111
+
112
+ Bug reports and pull requests are welcome on GitHub at https://github.com/clear-code/fluent-tail_checker.
113
+
114
+ ## Copyright
115
+
116
+ * Copyright 2025 Daijiro Fukuda
117
+ * License
118
+ * Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/Vagrantfile ADDED
@@ -0,0 +1,48 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ vms = [
9
+ {
10
+ :id => "ubuntu-xenial",
11
+ :box => "bento/ubuntu-16.04",
12
+ },
13
+ {
14
+ :id => "ubuntu-focal",
15
+ :box => "bento/ubuntu-20.04",
16
+ },
17
+ {
18
+ :id => "ubuntu-jammy",
19
+ :box => "bento/ubuntu-22.04",
20
+ },
21
+ {
22
+ :id => "centos-7",
23
+ :box => "bento/centos-7",
24
+ },
25
+ {
26
+ :id => "rockylinux-8",
27
+ :box => "bento/rockylinux-8",
28
+ },
29
+ {
30
+ :id => "almalinux-9",
31
+ :box => "bento/almalinux-9",
32
+ },
33
+ ]
34
+
35
+ n_cpus = ENV["BOX_N_CPUS"]&.to_i || 2
36
+ memory = ENV["BOX_MEMORY"]&.to_i || 2048
37
+ vms.each_with_index do |vm, idx|
38
+ id = vm[:id]
39
+ box = vm[:box] || id
40
+ config.vm.define(id) do |node|
41
+ node.vm.box = box
42
+ node.vm.provider("virtualbox") do |virtual_box|
43
+ virtual_box.cpus = n_cpus if n_cpus
44
+ virtual_box.memory = memory if memory
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
1
+ # Development
2
+
3
+ ## Quick start
4
+
5
+ ```console
6
+ $ bundle
7
+ $ bundle exec exe/fluent-tailcheck --version
8
+ $ bundle exec exe/fluent-tailcheck --help
9
+ $ bundle exec exe/fluent-tailcheck test/data/pos_duplicate_unwatched_path
10
+ ```
11
+
12
+ ## Unit test
13
+
14
+ ```console
15
+ $ bundle exec rake test
16
+ ```
17
+
18
+ ## Package test
19
+
20
+ Need `Vagrant`.
21
+
22
+ ```console
23
+ $ vagrant status
24
+ $ vagrant up {id}
25
+ $ vagrant snapshot save {id} init
26
+ $ vagrant ssh {id} -- /vagrant/test/script/{test-script}
27
+ $ vagrant snapshot restore {id} init
28
+ ```
29
+
30
+ Example:
31
+
32
+ ```console
33
+ $ vagrant up centos-7
34
+ $ vagrant snapshot save centos-7 init
35
+ $ vagrant ssh centos-7 -- /vagrant/test/script/td-agent-v3.1.1.el7-test.bash
36
+ $ vagrant snapshot restore centos-7 init
37
+ ```
38
+
39
+ ## Install and release
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/doc/feature.md ADDED
@@ -0,0 +1,50 @@
1
+ # Feature
2
+
3
+ `fluent-tailcheck` performs the following checks on the specified pos file.
4
+
5
+ * [Duplication check](#duplication-check)
6
+ * [Collection ratio check](#collection-ratio-check)
7
+
8
+ ## Duplication check
9
+
10
+ `fluent-tailcheck` checks whether there is any dulication in the specified pos files.
11
+
12
+ The keys of watching pos entries in one pos file must be unique.
13
+
14
+ By default, the key is the path of the target log file.
15
+ When using [follow_inodes](https://docs.fluentd.org/input/tail#follow_inodes), the key is the inode.
16
+
17
+ If duplication occurs, it means some anomalies occurs in that `in_tail`.
18
+ Especially, the following log missing issue causes this duplication.
19
+
20
+ > * https://github.com/fluent/fluentd/issues/3614
21
+ > * In case `follow_inodes false` (default setting), collection of a file may stop and continue to stop after log rotation.
22
+ > * Fixed since Fluentd v1.16.3 (fluent-package v5.0.2, td-agent v4.5.2).
23
+
24
+ ## Collection ratio check
25
+
26
+ `fluent-tailcheck` checks collection ratio of each watching pos entry.
27
+
28
+ By default, `fluent-tailcheck` detects log files that have not been collected up to 50% of the filesize.
29
+ You can change this threshold by `--ratio` option.
30
+
31
+ If this it too low, collection of those files may not be keeping up.
32
+ Or it may have stopped with some anomalies.
33
+
34
+ Especially, if the `in_tail` uses [follow_inodes](https://docs.fluentd.org/input/tail#follow_inodes), there is a known log missing issue that was fixed in Fluentd v1.16.2.
35
+
36
+ > * https://github.com/fluent/fluentd/issues/4190
37
+ > * In case `follow_inodes true`, collection of a file may stop and continue to stop after log rotation.
38
+ > * Fixed since Fluentd v1.16.2 (fluent-package v5.0.0, td-agent v4.5.1).
39
+
40
+ ### Limitation
41
+
42
+ `fluent-tailcheck` checks the sizes of logfiles based on the paths recorded in the pos files (except already unwatched pos entries).
43
+
44
+ However, if using `--follow-inodes`, there is a restriction on which files can be checked.
45
+ If using `--follow-inodes`, it is possible that `fluent-tailcheck` can not check the already rotated logfiles even if they are recorded in the pos files and are not unwatched yet.
46
+ Since the path recorded in the pos file is not updated after log rotation, the current path and inode may differ.
47
+ `fluent-tailcheck` checks only log files whose path and inode in the pos file match.
48
+ At least, it can check the current log files.
49
+
50
+ If not using `--follow-inodes`, this limitation does not exist.
@@ -0,0 +1,100 @@
1
+ # Installation
2
+
3
+ ## fluent-package
4
+
5
+ ### RPM/DEB (Linux)
6
+
7
+ ```console
8
+ $ sudo fluent-gem install fluent-tail_checker
9
+ ```
10
+
11
+ Then, you can use the command as follows.
12
+
13
+ ```console
14
+ $ /opt/fluent/bin/fluent-tailcheck --help
15
+ ```
16
+
17
+ ### .msi (Windows)
18
+
19
+ `Fluent Package Command Prompt` with Administrator privilege:
20
+
21
+ ```console
22
+ $ fluent-gem install fluent-tail_checker
23
+ ```
24
+
25
+ Then, you can use the command as follows.
26
+
27
+ ```console
28
+ $ fluent-tailcheck --help
29
+ ```
30
+
31
+ ## td-agent v4
32
+
33
+ ### RPM/DEB (Linux)
34
+
35
+ ```console
36
+ $ sudo td-agent-gem install fluent-tail_checker
37
+ ```
38
+
39
+ Then, you can use the command as follows.
40
+
41
+ ```console
42
+ $ /opt/td-agent/bin/fluent-tailcheck --help
43
+ ```
44
+
45
+ ### .msi (Windows)
46
+
47
+ `Td-agent Command Prompt` with Administrator privilege:
48
+
49
+ ```console
50
+ $ td-agent-gem install fluent-tail_checker
51
+ ```
52
+
53
+ Then, you can use the command as follows.
54
+
55
+ ```console
56
+ $ fluent-tailcheck --help
57
+ ```
58
+
59
+ ## td-agent v3
60
+
61
+ ### RPM/DEB (Linux)
62
+
63
+ ```console
64
+ $ sudo td-agent-gem install fluent-tail_checker --bindir /opt/td-agent/embedded/bin
65
+ ```
66
+
67
+ Then, you can use the command as follows.
68
+
69
+ ```console
70
+ $ /opt/td-agent/embedded/bin/fluent-tailcheck --help
71
+ ```
72
+
73
+ Note: On td-agent v3, you need to specify `--bindir /opt/td-agent/embedded/bin` to install the executable under `/opt/td-agent/embedded/bin`.
74
+ Without this, the executable will be installed under `/opt/td-agent/embedded/lib/ruby/gems/2.4.0/bin/`.
75
+
76
+ ### .msi (Windows)
77
+
78
+ `Td-agent Command Prompt` with Administrator privilege:
79
+
80
+ ```console
81
+ $ fluent-gem install fluent-tail_checker
82
+ ```
83
+
84
+ Then, you can use the command as follows.
85
+
86
+ ```console
87
+ $ fluent-tailcheck --help
88
+ ```
89
+
90
+ ## Your Ruby environment
91
+
92
+ ```console
93
+ $ gem install fluent-tail_checker
94
+ ```
95
+
96
+ Then, you can use the command as follows.
97
+
98
+ ```console
99
+ $ fluent-tailcheck --help
100
+ ```
@@ -0,0 +1,85 @@
1
+ # Result examples
2
+
3
+ ## No anomalies found
4
+
5
+ ```
6
+ Check /path/to/pos.
7
+ Done duplication check for 2 PosEntries.
8
+ Done collection ratio check for 2 files.
9
+
10
+ All check completed. (Fluentd v1.15.0)
11
+ There is no anomalies.
12
+ ```
13
+
14
+ This means:
15
+
16
+ * The command has checked `/path/to/pos`.
17
+ * The command has checked 2 pos entries for duplication check.
18
+ * The command has checked 2 files for collection ratio check.
19
+ * It is detected that the version of your Fluentd is v1.15.0.
20
+ * There is no anomalies.
21
+
22
+ ## Pos duplication found
23
+
24
+ ```
25
+ Check /path/to/pos.
26
+ Done duplication check for 3 PosEntries.
27
+ Duplicated PosEntries are found. This is a known log missing issue that was fixed in Fluentd v1.16.3 (fluent-package v5.0.2, td-agent v4.5.2). If you are using any version older than these, updating Fluentd will resolve the issue.
28
+ Duplicated paths:
29
+ /test/foo.log
30
+ Done collection ratio check for 0 files.
31
+
32
+ All check completed. (Fluentd v1.15.0)
33
+ Some anomalies are found. Please check the logs for details.
34
+
35
+ If you have any questions or issues, please report them to the following:
36
+ Fluentd Q&A: https://github.com/fluent/fluentd/discussions/categories/q-a
37
+ Fluentd Q&A (日本語用): https://github.com/fluent/fluentd/discussions/categories/q-a-japanese
38
+ About this command (日本語可): https://github.com/clear-code/fluent-tail_checker/issues
39
+ ```
40
+
41
+ In this case, some the pos entries are duplicated.
42
+ It is a known log missing issue that was fixed in Fluentd v1.16.3.
43
+
44
+ > * https://github.com/fluent/fluentd/issues/3614
45
+ > * In case `follow_inodes false` (default setting), collection of a file may stop and continue to stop after log rotation.
46
+ > * Fixed since Fluentd v1.16.3 (fluent-package v5.0.2, td-agent v4.5.2).
47
+
48
+ So, you should check whether there is any log missing, and consider updating Fluentd, especially, if you are using any version older than Fluentd v1.16.3 (fluent-package v5.0.2, td-agent v4.5.2).
49
+
50
+ ## Too low collection ratio file found
51
+
52
+ ```
53
+ Check /path/to/pos.
54
+ Done duplication check for 2 PosEntries.
55
+ Done collection ratio check for 2 files.
56
+ Collection ratio of some files are too low. Collection of those files may not be keeping up. Or it may have stopped with some anomalies. This can be a known log missing issue of the follow_inodes feature that was fixed in Fluentd v1.16.2 (fluent-package v5.0.0, td-agent v4.5.1). If you are using any version older than these, updating Fluentd will resolve the issue.
57
+ Filepaths with too low collection ratio (threshold: 0.5):
58
+ /test/bar.log (ratio: 0.2)
59
+ /test/foo.log (ratio: 0.1)
60
+
61
+ All check completed. (Fluentd v1.15.0)
62
+ Some anomalies are found. Please check the logs for details.
63
+
64
+ If you have any questions or issues, please report them to the following:
65
+ Fluentd Q&A: https://github.com/fluent/fluentd/discussions/categories/q-a
66
+ Fluentd Q&A (日本語用): https://github.com/fluent/fluentd/discussions/categories/q-a-japanese
67
+ About this command (日本語可): https://github.com/clear-code/fluent-tail_checker/issues
68
+ ```
69
+
70
+ In this case, collection ratio of some target files are too low.
71
+ Collection of those files may have stopped or may not be keeping up.
72
+
73
+ > /test/bar.log (ratio: 0.2)
74
+
75
+ This means that only 20% of the data of the file is collected for the filesize.
76
+ If it is not keeping up temporarily, then it is no problem.
77
+ If this is always the case, or if collection has stopped completely, then log missing may occur.
78
+
79
+ Especially, if the `in_tail` uses [follow_inodes](https://docs.fluentd.org/input/tail#follow_inodes), there is a known log missing issue that was fixed in Fluentd v1.16.2.
80
+
81
+ > * https://github.com/fluent/fluentd/issues/4190
82
+ > * In case `follow_inodes true`, collection of a file may stop and continue to stop after log rotation.
83
+ > * Fixed since Fluentd v1.16.2 (fluent-package v5.0.0, td-agent v4.5.1).
84
+
85
+ Please consider updating Fluentd if you are using any version older than Fluentd v1.16.2 (td-agent v4.5.1).
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "fluent/tail_checker"
5
+
6
+ command = Fluent::TailChecker::TailCheck.new
7
+ exit(command.run)
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 Daijiro Fukuda
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "fluent/env"
18
+
19
+ # For compatibility with Fluentd v1.15.2 and earlier.
20
+ # See https://github.com/fluent/fluentd/pull/3883
21
+ begin
22
+ require "fluent/file_wrapper"
23
+ rescue LoadError
24
+ if Fluent.windows?
25
+ require "fluent/plugin/file_wrapper"
26
+ else
27
+ Fluent::FileWrapper = File
28
+ end
29
+ end
30
+
31
+ module Fluent
32
+ module TailChecker
33
+ class CollectionRatioChecker
34
+ def initialize(posfile, follow_inodes, collection_ratio_threshold)
35
+ @posfile = posfile
36
+ @follow_inodes = follow_inodes
37
+ @collection_ratio_threshold = collection_ratio_threshold
38
+ end
39
+
40
+ def check
41
+ unacceptable_collection_ratio_found = false
42
+ unacceptable_collection_ratio_path_and_ratio_list = []
43
+ checked_file_counts = 0
44
+
45
+ @posfile.watching_entries.each do |entry|
46
+ size = get_file_size(entry)
47
+ next if size.nil?
48
+
49
+ checked_file_counts += 1
50
+ ratio = collection_ratio(entry.pos, size)
51
+ if ratio < @collection_ratio_threshold
52
+ unacceptable_collection_ratio_found = true
53
+ unacceptable_collection_ratio_path_and_ratio_list.push([entry.path, ratio])
54
+ end
55
+ end
56
+
57
+ puts "Done collection ratio check for #{checked_file_counts} files."
58
+
59
+ if unacceptable_collection_ratio_found
60
+ log_issue(unacceptable_collection_ratio_path_and_ratio_list)
61
+ return false
62
+ end
63
+
64
+ true
65
+ end
66
+
67
+ def get_file_size(pos_entry)
68
+ if @follow_inodes
69
+ get_file_size_from_inode(pos_entry)
70
+ else
71
+ get_file_size_from_path(pos_entry)
72
+ end
73
+ end
74
+
75
+ def get_file_size_from_path(pos_entry)
76
+ size = FileTest.size?(pos_entry.path)
77
+ unless size
78
+ $stderr.puts "Skip #{pos_entry.path} because it is not found. Make sure you have the proper privilege, e.g. 'sudo'."
79
+ end
80
+ size
81
+ end
82
+
83
+ def get_file_size_from_inode(pos_entry)
84
+ unless FileTest.exist?(pos_entry.path)
85
+ $stderr.puts "Skip #{pos_entry.path} because it is not found. Make sure you have the proper privilege, e.g. 'sudo'."
86
+ return nil
87
+ end
88
+
89
+ stat = Fluent::FileWrapper.stat(pos_entry.path)
90
+ # If follow_inodes is enabled, the inode of the current logfile should match the inode in the pos_file.
91
+ # It may not match for the rotated logfiles because the path info in the pos_file is not updated.
92
+ # So, at least, check the current logfile.
93
+ # For rotated logfiles, check them if inode matches.
94
+ return nil unless stat.ino == pos_entry.ino
95
+
96
+ stat.size
97
+ end
98
+
99
+ def collection_ratio(pos, file_size)
100
+ return 1.0 if file_size == 0
101
+
102
+ pos.to_f / file_size
103
+ end
104
+
105
+ def log_issue(path_and_ratio_list)
106
+ if @follow_inodes
107
+ puts "Collection ratio of some files are too low. Collection of those files may not be keeping up. Or it may have stopped with some anomalies. This can be a known log missing issue of the follow_inodes feature that was fixed in Fluentd v1.16.2 (fluent-package v5.0.0, td-agent v4.5.1). If you are using any version older than these, updating Fluentd will resolve the issue."
108
+ else
109
+ puts "Collection ratio of some files are too low. Collection of those files may not be keeping up. Or it may have stopped with some anomalies. It is recommended to verify whether there is any log missing."
110
+ end
111
+
112
+ puts "Filepaths with too low collection ratio (threshold: #{@collection_ratio_threshold}):"
113
+ path_and_ratio_list.each do |path, ratio|
114
+ puts " #{path} (ratio: #{ratio})"
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 Daijiro Fukuda
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "set"
18
+
19
+ module Fluent
20
+ module TailChecker
21
+ class DuplicatedPosChecker
22
+ def initialize(posfile, follow_inodes)
23
+ @posfile = posfile
24
+ @follow_inodes = follow_inodes
25
+ end
26
+
27
+ def check
28
+ duplicated_key_found = false
29
+ key_set = Set.new
30
+ duplicated_key_set = Set.new
31
+ checked_key_counts = 0
32
+
33
+ @posfile.watching_entries.map do |entry|
34
+ @follow_inodes ? entry.ino : entry.path
35
+ end.each do |key|
36
+ checked_key_counts += 1
37
+ next if key_set.add?(key)
38
+
39
+ duplicated_key_found = true
40
+ duplicated_key_set.add(key)
41
+ end
42
+
43
+ puts "Done duplication check for #{checked_key_counts} PosEntries."
44
+
45
+ if duplicated_key_found
46
+ log_issue(duplicated_key_set)
47
+ return false
48
+ end
49
+
50
+ true
51
+ end
52
+
53
+ def log_issue(duplicated_keys)
54
+ if @follow_inodes
55
+ puts "Duplicated PosEntries are found. Unknown anomalies may be occurring. It is recommended to verify whether there is any log missing."
56
+ puts "Duplicated inodes:"
57
+ else
58
+ puts "Duplicated PosEntries are found. This is a known log missing issue that was fixed in Fluentd v1.16.3 (fluent-package v5.0.2, td-agent v4.5.2). If you are using any version older than these, updating Fluentd will resolve the issue."
59
+ puts "Duplicated paths:"
60
+ end
61
+
62
+ duplicated_keys.each do |key|
63
+ puts " #{key}"
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 Daijiro Fukuda
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Fluent
18
+ module TailChecker
19
+ UNWATCHED_POSITION = 0xffffffffffffffff
20
+ POSITION_FILE_ENTRY_REGEX = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/
21
+
22
+ class PosFile
23
+ attr_reader :entries
24
+
25
+ def initialize(entries)
26
+ @entries = entries
27
+ end
28
+
29
+ def self.load(path)
30
+ PosFile.new(PosFile.load_entries(path))
31
+ end
32
+
33
+ def self.load_entries(path)
34
+ entries = []
35
+
36
+ File.open(path, File::RDONLY|File::BINARY) do |file|
37
+ file.each_line do |line|
38
+ m = POSITION_FILE_ENTRY_REGEX.match(line)
39
+ next if m.nil?
40
+
41
+ entries << PosEntry.new(
42
+ m[1],
43
+ m[2].to_i(16),
44
+ m[3].to_i(16),
45
+ )
46
+ end
47
+ end
48
+
49
+ entries
50
+ end
51
+
52
+ def watching_entries
53
+ entries.select do |entry|
54
+ not entry.unwatched?
55
+ end
56
+ end
57
+ end
58
+
59
+ class PosEntry
60
+ attr_reader :path, :pos, :ino
61
+
62
+ def initialize(path, pos, ino)
63
+ @path = path
64
+ @pos = pos
65
+ @ino = ino
66
+ end
67
+
68
+ def unwatched?
69
+ @pos == UNWATCHED_POSITION
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 Daijiro Fukuda
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "optparse"
18
+ require "fluent/version"
19
+
20
+ require_relative "pos"
21
+ require_relative "duplicated_pos_checker"
22
+ require_relative "collection_ratio_checker"
23
+
24
+ module Fluent
25
+ module TailChecker
26
+ class TailCheck
27
+ def initialize
28
+ @pos_filepaths = []
29
+ @follow_inodes = false
30
+ @collection_ratio_threshold = 0.5
31
+ end
32
+
33
+ def run(argv=ARGV)
34
+ parse_command_line(argv)
35
+ @pos_filepaths = validate_paths(@pos_filepaths).to_a
36
+ check
37
+ end
38
+
39
+ def parse_command_line(argv)
40
+ parser = OptionParser.new
41
+ parser.version = VERSION
42
+ parser.banner = <<~BANNER
43
+ Usage: fluent-tailcheck [OPTIONS] POS_FILE...
44
+ Example: fluent-tailcheck /path/to/pos1 /path/to/pos2
45
+ Example: fluent-tailcheck /path/to/pos/*
46
+ Example: fluent-tailcheck --follow-inodes /path/to/pos_with_follow_inodes
47
+
48
+ Requires read permission to the specified pos files and the target log files.
49
+ Example: sudo fluent-tailcheck /path/to/pos1
50
+
51
+ Document: https://github.com/clear-code/fluent-tail_checker/blob/main/README.md
52
+
53
+ If you have any issues with this command, please report it to https://github.com/clear-code/fluent-tail_checker/issues.
54
+
55
+ Options:
56
+ BANNER
57
+
58
+ parser.on("--follow-inodes", "Check the specified pos files with the condition that the follow_inodes feature is enabled.", "Default: Disabled") do
59
+ @follow_inodes = true
60
+ end
61
+ parser.on("--ratio NUM", Float, "Minimum ratio of collection of each target log file to accept.", "Default: #{@collection_ratio_threshold}") do |v|
62
+ @collection_ratio_threshold = v
63
+ end
64
+
65
+ begin
66
+ @pos_filepaths = parser.parse(argv)
67
+
68
+ if @collection_ratio_threshold < 0 or @collection_ratio_threshold > 1
69
+ raise OptionParser::InvalidArgument, "--ratio #{@collection_ratio_threshold} must be an decimal from 0 to 1."
70
+ end
71
+ rescue OptionParser::ParseError => e
72
+ $stderr.puts e, "", parser.help, ""
73
+ raise
74
+ end
75
+ end
76
+
77
+ def validate_paths(paths)
78
+ Enumerator.new do |y|
79
+ paths.each do |path|
80
+ unless FileTest.exist?(path)
81
+ $stderr.puts "Skip #{path} because it is not found. Make sure you have the proper privilege, e.g. 'sudo'."
82
+ next
83
+ end
84
+
85
+ y << path
86
+ end
87
+ end
88
+ end
89
+
90
+ def check
91
+ if @pos_filepaths.empty?
92
+ $stderr.puts "No pos_file to be checked. Please specify valid pos_file paths."
93
+ return false
94
+ end
95
+
96
+ succeeded = true
97
+
98
+ @pos_filepaths.each do |path|
99
+ puts "\nCheck #{path}."
100
+ pos_file = try_to_open_pos_file(path)
101
+ next if pos_file.nil?
102
+
103
+ succeeded = DuplicatedPosChecker.new(pos_file, @follow_inodes).check && succeeded
104
+ succeeded = CollectionRatioChecker.new(pos_file, @follow_inodes, @collection_ratio_threshold).check && succeeded
105
+ end
106
+
107
+ puts "\nAll check completed. (Fluentd v#{Fluent::VERSION})"
108
+
109
+ unless succeeded
110
+ puts "Some anomalies are found. Please check the logs for details.",
111
+ "",
112
+ "If you have any questions or issues, please report them to the following:",
113
+ " Fluentd Q&A: https://github.com/fluent/fluentd/discussions/categories/q-a",
114
+ " Fluentd Q&A (日本語用): https://github.com/fluent/fluentd/discussions/categories/q-a-japanese",
115
+ " About this command (日本語可): https://github.com/clear-code/fluent-tail_checker/issues"
116
+ return false
117
+ end
118
+
119
+ puts "There is no anomalies."
120
+ true
121
+ end
122
+
123
+ def try_to_open_pos_file(path)
124
+ PosFile.load(path)
125
+ rescue => e
126
+ $stderr.puts "Can not open the file. Skipped. Make sure you have the proper privilege, e.g. 'sudo'. Path: #{path}, Error: #{e}"
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 Daijiro Fukuda
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Fluent
18
+ module TailChecker
19
+ VERSION = "1.0.0"
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 Daijiro Fukuda
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative "tail_checker/tail_check"
18
+ require_relative "tail_checker/version"
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-tail_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daijiro Fukuda
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fluentd
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ description: A script to check that in_tail plugin of Fluentd is working properly.
27
+ email:
28
+ - fukuda@clear-code.com
29
+ executables:
30
+ - fluent-tailcheck
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - Vagrantfile
38
+ - doc/development.md
39
+ - doc/feature.md
40
+ - doc/installation.md
41
+ - doc/result-examples.md
42
+ - exe/fluent-tailcheck
43
+ - lib/fluent/tail_checker.rb
44
+ - lib/fluent/tail_checker/collection_ratio_checker.rb
45
+ - lib/fluent/tail_checker/duplicated_pos_checker.rb
46
+ - lib/fluent/tail_checker/pos.rb
47
+ - lib/fluent/tail_checker/tail_check.rb
48
+ - lib/fluent/tail_checker/version.rb
49
+ homepage: https://github.com/clear-code/fluent-tail_checker
50
+ licenses:
51
+ - Apache-2.0
52
+ metadata:
53
+ homepage_uri: https://github.com/clear-code/fluent-tail_checker
54
+ source_code_uri: https://github.com/clear-code/fluent-tail_checker
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.6.8
70
+ specification_version: 4
71
+ summary: A script to check that in_tail plugin of Fluentd is working properly.
72
+ test_files: []