fluent-plugin-diskfree 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: bc13110930756dfc7f08a4c696775794e357f5b1d80ec98f1efbe74c31f4b098
4
+ data.tar.gz: 76107771c47453d8af14bf0a260b140951ea64471e5be707f9ad1ae1d0253934
5
+ SHA512:
6
+ metadata.gz: 926641a3321470376924e3c147715dc68cb498e9b42f2118dfb14f0dd51409d7e88273d1bd41a7f4c3da9f5be1648c77a2e82dee8065b3bad3d67ee1dc846f9e
7
+ data.tar.gz: 75d5a2cbc8519750986a46a05033a4407eaef1a5d56fe945053c66c8187f597df4814d139415157d4681d9f90513f506b94b331a552d82f4ceb43612d8b94d84
@@ -0,0 +1,20 @@
1
+ #### 問題 / Problem
2
+
3
+ ...
4
+
5
+ #### 再現方法 / Steps to replicate
6
+
7
+ ...
8
+
9
+ #### 期待される結果 / Expected Behavior
10
+
11
+ ...
12
+
13
+ #### 実行環境 / Your environment
14
+
15
+ * OSのバージョン / OS version
16
+
17
+ * 利用しているfluentd, td-agentのバージョン / paste result of ``fluentd --version`` or ``td-agent --version``
18
+
19
+ * 使用中のプラグインバージョン / plugin version
20
+ * fluentd, td-agentの起動ログ / paste boot log of fluentd or td-agent
@@ -0,0 +1,20 @@
1
+ <!-- Issue 番号がない PR は受け付けません。 -->
2
+ <!-- We don't accept PRs which has no Issue ID. -->
3
+
4
+ ## 👏 解決する issue / Resolved Issues
5
+ - close #0
6
+ - close #0
7
+
8
+ ## 📝 関連する issue / Related Issues
9
+ - #0
10
+ - #0
11
+
12
+ ## ⛏ 変更内容 / Details of Changes
13
+ <!-- 変更を端的に箇条書きで -->
14
+ <!-- List down your changes concisely -->
15
+ - xxxxxx
16
+ - xxx
17
+
18
+ ## 📸 スクリーンショット / Screenshots
19
+ <!-- スタイルなどの変更の場合はスクリーンショットがあるとレビューしやすいです -->
20
+ <!-- Changes in styles would be easier to review with screenshots! -->
@@ -0,0 +1,42 @@
1
+ name: GitHub-Actions
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ paths-ignore:
7
+ - .github/**
8
+ - bin/**
9
+ - .gitignore
10
+ - .rspec
11
+ - CHANGELOG.md
12
+ - CODE_OF_CONDUCT.md
13
+ - LICENSE.txt
14
+ - README.md
15
+ pull_request:
16
+
17
+ jobs:
18
+ rspec:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - name: Check out code
22
+ uses: actions/checkout@v2
23
+ - uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: 2.6.6
26
+ bundler-cache: true
27
+ - name: Test with Rspec
28
+ run: bundle exec rspec
29
+ rubocop:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Check out code
33
+ uses: actions/checkout@v2
34
+ - uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: 2.6.6
37
+ - name: rubocop
38
+ uses: reviewdog/action-rubocop@v1
39
+ with:
40
+ rubocop_version: gemfile
41
+ github_token: ${{ secrets.github_token }}
42
+ reporter: github-pr-review # Default is github-pr-check
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,180 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/*.rb'
4
+ Exclude:
5
+ - ''
6
+ - 'vendor/**/*'
7
+ - '.git/**/*'
8
+ - 'bin/*'
9
+ NewCops: enable
10
+ TargetRubyVersion: 2.6.6
11
+ SuggestExtensions: false
12
+
13
+ Layout/BeginEndAlignment:
14
+ Enabled: true
15
+
16
+ Layout/EmptyLinesAroundAttributeAccessor:
17
+ Enabled: true
18
+
19
+ Layout/SpaceAroundMethodCallOperator:
20
+ Enabled: true
21
+
22
+ Lint/BinaryOperatorWithIdenticalOperands:
23
+ Enabled: true
24
+
25
+ Lint/ConstantDefinitionInBlock:
26
+ Enabled: true
27
+
28
+ Lint/DeprecatedOpenSSLConstant:
29
+ Enabled: true
30
+
31
+ Lint/DuplicateElsifCondition:
32
+ Enabled: true
33
+
34
+ Lint/DuplicateRequire:
35
+ Enabled: true
36
+
37
+ Lint/DuplicateRescueException:
38
+ Enabled: true
39
+
40
+ Lint/EmptyConditionalBody:
41
+ Enabled: true
42
+
43
+ Lint/EmptyFile:
44
+ Enabled: true
45
+
46
+ Lint/FloatComparison:
47
+ Enabled: true
48
+
49
+ Lint/IdentityComparison:
50
+ Enabled: true
51
+
52
+ Lint/MissingSuper:
53
+ Enabled: true
54
+
55
+ Lint/MixedRegexpCaptureTypes:
56
+ Enabled: true
57
+
58
+ Lint/OutOfRangeRegexpRef:
59
+ Enabled: true
60
+
61
+ Lint/RaiseException:
62
+ Enabled: true
63
+
64
+ Lint/SelfAssignment:
65
+ Enabled: true
66
+
67
+ Lint/StructNewOverride:
68
+ Enabled: true
69
+
70
+ Lint/TopLevelReturnWithArgument:
71
+ Enabled: true
72
+
73
+ Lint/TrailingCommaInAttributeDeclaration:
74
+ Enabled: true
75
+
76
+ Lint/UnreachableLoop:
77
+ Enabled: true
78
+
79
+ Lint/UselessMethodDefinition:
80
+ Enabled: true
81
+
82
+ Lint/UselessTimes:
83
+ Enabled: true
84
+
85
+ Style/AccessorGrouping:
86
+ Enabled: true
87
+
88
+ Style/ArrayCoercion:
89
+ Enabled: true
90
+
91
+ Style/BisectedAttrAccessor:
92
+ Enabled: true
93
+
94
+ Style/CaseLikeIf:
95
+ Enabled: true
96
+
97
+ Style/CombinableLoops:
98
+ Enabled: true
99
+
100
+ Style/ExplicitBlockArgument:
101
+ Enabled: true
102
+
103
+ Style/ExponentialNotation:
104
+ Enabled: true
105
+
106
+ Style/GlobalStdStream:
107
+ Enabled: true
108
+
109
+ Style/HashAsLastArrayItem:
110
+ Enabled: true
111
+
112
+ Style/HashEachMethods:
113
+ Enabled: true
114
+
115
+ Style/HashLikeCase:
116
+ Enabled: true
117
+
118
+ Style/HashTransformKeys:
119
+ Enabled: true
120
+
121
+ Style/HashTransformValues:
122
+ Enabled: true
123
+
124
+ Style/KeywordParametersOrder:
125
+ Enabled: true
126
+
127
+ Style/OptionalBooleanParameter:
128
+ Enabled: true
129
+
130
+ Style/RedundantAssignment:
131
+ Enabled: true
132
+
133
+ Style/RedundantFetchBlock:
134
+ Enabled: true
135
+
136
+ Style/RedundantFileExtensionInRequire:
137
+ Enabled: true
138
+
139
+ Style/RedundantRegexpCharacterClass:
140
+ Enabled: true
141
+
142
+ Style/RedundantRegexpEscape:
143
+ Enabled: true
144
+
145
+ Style/RedundantSelfAssignment:
146
+ Enabled: true
147
+
148
+ Style/SingleArgumentDig:
149
+ Enabled: true
150
+
151
+ Style/SlicingWithRange:
152
+ Enabled: true
153
+
154
+ Style/SoleNestedConditional:
155
+ Enabled: true
156
+
157
+ Style/StringConcatenation:
158
+ Enabled: true
159
+
160
+ Style/StringLiteralsInInterpolation:
161
+ Enabled: true
162
+ EnforcedStyle: double_quotes
163
+
164
+ Layout/LineLength:
165
+ Max: 120
166
+
167
+ Style/ClassAndModuleChildren:
168
+ EnforcedStyle: nested
169
+
170
+ Metrics/MethodLength:
171
+ Max: 30
172
+
173
+ Metrics/AbcSize:
174
+ Max: 50
175
+
176
+ Metrics/BlockLength:
177
+ Max: 35
178
+
179
+ Style/FloatDivision:
180
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.1] - 2021-07-13
4
+
5
+ - Create RSpec test.
6
+ - Modify private method.
7
+
8
+ ## [0.1.0] - 2021-07-13
9
+
10
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Dockerfile ADDED
@@ -0,0 +1,3 @@
1
+ FROM fluent/fluentd:latest
2
+
3
+ USER root
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in fluent-plugin-diskfree.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 h.nomura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # fluent-plugin-diskfree, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ [![GitHub-Actions](https://github.com/nomunomu0504/fluent-plugin-diskfree/actions/workflows/rubocop.yml/badge.svg?branch=master)](https://github.com/nomunomu0504/fluent-plugin-diskfree/actions/workflows/rubocop.yml)
4
+
5
+ # What is this
6
+
7
+ **fluent-plugin-diskfree** is a [fluentd](http://fluentd.org "fluentd") input plugin for getting disk usage information.
8
+
9
+ ## Requirements
10
+
11
+ | fluent-plugin-diskfree | fluentd | ruby |
12
+ |:----------------------:|:-------:|:----:|
13
+ | >= 0.1.0 | >= v1.3, < v2.0 | >= 2.6.6 |
14
+
15
+ # How to Install
16
+
17
+ Adding the line to install from Gemfile:
18
+
19
+ gem 'fluent-plugin-diskfree'
20
+
21
+ execute command `gem install`:
22
+
23
+ $ gem install fluent-plugin-diskfree
24
+
25
+ [td-agent](https://docs.fluentd.org/installation/install-by-rpm#what-is-td-agent) has its own Ruby ecosystem.
26
+ If you have installed td-agent, you would use `gem` command included with td-agent.
27
+
28
+ $ sudo /path/to/fluent/ruby/bin/gem isntall fluent-plugin-diskfree
29
+
30
+ # Usage
31
+
32
+ <source>
33
+ @type diskfree
34
+ option -k # linux df command option
35
+ refresh_interval 5 # execute refresh interval in seconds
36
+ mounted_path / # path to check disk usage
37
+ trim_percent true # trim percent from result
38
+ replace_separator true # replace separator of result mount_path to '_'
39
+ tag_prefix diskfree # tag prefix
40
+ </source>
41
+
42
+ # Configuration
43
+
44
+ name | type | default value | description
45
+ -----|------|-----|------
46
+ option | string | -k | linux df command option
47
+ refresh_interval | integer | 5 | execute refresh interval in seconds
48
+ mounted_path | string | / | path to check disk usage
49
+ trim_percent | bool | true | trim percent from result
50
+ replace_separator | bool | true | replace separator of result mount_path to '_'
51
+ tag_prefix | string | diskfree | tag prefix
52
+
53
+ # How To Test
54
+
55
+ They can testing by using [rspec](https://github.com/rspec/rspec-core "rspec") and [fluent-plugin-testing](https://github.com/fluent/fluent-plugin-testing "fluent-plugin-testing").
56
+
57
+ ## RSpec Test
58
+ $ bundle exec rspec
59
+
60
+ ## Ruby Linter Test(rubocop)
61
+ $ bundle exec rubocop
62
+
63
+ ## Ruby Linter Test(rubocop - auto correct)
64
+ $ bundle exec rubocop --auto-correct
65
+
66
+ # Operation Verification
67
+
68
+ They can using Dockerfile and docker-compose.yml to verify the operation of the plugin.
69
+
70
+ $ docker-compose run fluentd ash
71
+
72
+ In the fluentd container, execute command below:
73
+
74
+ / $ fluentd -c /fluentd/etc/fluent.conf -p /fluentd/plugin
75
+
76
+ ※ These files are hot-loaded since fluent.conf and the plugin folder are volume mounted by docker-compose.
77
+
78
+ # Legal Notification
79
+
80
+ ## Copyright
81
+
82
+ Copyright (c) 2021 h.nomura
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the MIT License.
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the Fluent::Plugin::DiskFree project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nomunomu0504/fluent-plugin-diskfree/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+ require "rspec/core/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+ RSpec::Core::RakeTask.new("spec")
9
+
10
+ task default: [:spec, :rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "fluent/plugin/diskfree"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ version: "3.3"
2
+
3
+ services:
4
+ fluentd:
5
+ build: .
6
+ container_name: fluentd_diskfeee_dev
7
+ command: "fluentd -c /fluentd/fluent.conf -p /fluentd/plugin"
8
+ volumes:
9
+ - ./lib/fluent/plugin:/fluentd/plugin
10
+ - ./fluent.conf:/fluentd/etc/fluent.conf
11
+ ports:
12
+ - "24224:24224"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "fluent-plugin-diskfree"
5
+ spec.version = '0.1.0'
6
+ spec.authors = ["h.nomura"]
7
+ spec.email = ["h.nomura0504@gmail.com"]
8
+
9
+ spec.summary = "execute linux df command plugin for fluent."
10
+ spec.description = "execute linux df command plugin for fluent."
11
+ spec.homepage = "https://github.com/nomunomu0504/fluent-plugin-diskfree"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = ">= 2.6.6"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/nomunomu0504/fluent-plugin-diskfree"
17
+ spec.metadata["changelog_uri"] = "https://github.com/nomunomu0504/fluent-plugin-diskfree/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ # spec.add_dependency "example-gem", "~> 1.0"
30
+ spec.add_dependency "fluentd", ">= 1.3", "< 2"
31
+ spec.add_development_dependency "bundler", "~> 2.2.23"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
+ spec.add_development_dependency "rubocop", "~> 1.18.3"
34
+ spec.add_development_dependency "test-unit"
35
+ spec.add_development_dependency "rspec"
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
data/fluent.conf ADDED
@@ -0,0 +1,11 @@
1
+ <source>
2
+ @type diskfree
3
+ option -k
4
+ mounted_path /fluentd/plugin
5
+ replace_separator false
6
+ tag_prefix diskfree_dev
7
+ </source>
8
+
9
+ <match diskfree_dev.**>
10
+ @type stdout
11
+ </match>
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fluent/plugin/input'
4
+
5
+ #--------------------------------------------
6
+ # Fluentd linux Disk free command plugin
7
+ # refs: https://docs.fluentd.org/plugin-development
8
+ #--------------------------------------------
9
+ module Fluent
10
+ module Plugin
11
+ # Disk free command plugin class.
12
+ class DiskFree < Fluent::Plugin::Input
13
+ # Register Plugin to Fluent Input type.
14
+ Fluent::Plugin.register_input('diskfree', self)
15
+
16
+ # Load fluentd timer helper.
17
+ # refs: https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-timer
18
+ helpers :timer
19
+
20
+ # Load fluentd event emitter helper.
21
+ # refs: https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-event-emitter
22
+ helpers :event_emitter
23
+
24
+ #-------------------------------------
25
+ # df header cols length
26
+ # Filesystem, 1024-blocks, Used, Available, Capacity, Mounted on
27
+ #-------------------------------------
28
+ DF_HEADER_COLMUS_LENGTH = 6
29
+
30
+ #-------------------------------------
31
+ # Configuration for Diskfree Params
32
+ #-------------------------------------
33
+ # --block-size=1K
34
+ config_param :option, :string, default: '-k'
35
+ # 5[sec]
36
+ config_param :refresh_interval, :integer, default: 5
37
+ # default is root path.
38
+ config_param :mounted_path, :string, default: '/'
39
+ # trim percent from Used
40
+ config_param :trim_percent, :bool, default: true
41
+ # replace / with _ in mounted_path
42
+ config_param :replace_separator, :bool, default: true
43
+ # default nil, if exists output tag is #{tag_prefix}.#{mounted_path}
44
+ config_param :tag_prefix, :string, default: 'diskfree'
45
+
46
+ #-------------------------------------
47
+ # Fluent plugin configuration method.
48
+ #-------------------------------------
49
+ def configure(conf)
50
+ super
51
+ # -P: use the POSIX output format
52
+ @execute_command = "df -P #{@option} #{@mounted_path} 2> /dev/null"
53
+ end
54
+
55
+ #-------------------------------------
56
+ # Fluent plugin multi worker
57
+ #-------------------------------------
58
+ def multi_workers_ready?
59
+ true
60
+ end
61
+
62
+ #-------------------------------------
63
+ # Fluent plugin start method.
64
+ #-------------------------------------
65
+ def start
66
+ super
67
+ timer_execute(:in_diskfree, @refresh_interval, repeat: true, &method(:run_timer))
68
+ end
69
+
70
+ #-------------------------------------
71
+ # Private method
72
+ #-------------------------------------
73
+ private
74
+
75
+ #-------------------------------
76
+ # Main method
77
+ #-------------------------------
78
+ def diskfree
79
+ # Get df output. splited by line.
80
+ result = `#{@execute_command}`.split(/\R/)
81
+ # Remove df output header.
82
+ result.shift
83
+ result.map do |line|
84
+ # split by space.
85
+ data_list = line.split(/\s+/)
86
+ # check header colmus length.
87
+ log.error("Invalid df output format. #{line}") unless data_list.length == DF_HEADER_COLMUS_LENGTH
88
+ # Calclate disk free percent.
89
+ used_percent = ((data_list[2].to_f / data_list[1].to_f) * 100).floor(2)
90
+ available_percent = ((data_list[3].to_f / data_list[1].to_f) * 100).floor(2)
91
+ # output data.
92
+ disk_info = {
93
+ 'mounted_path' => replace_separator?(data_list[5]),
94
+ 'disksize' => data_list[1].to_i,
95
+ 'used' => data_list[2].to_i,
96
+ 'used_percent' => @trim_percent ? used_percent : "#{used_percent}%",
97
+ 'available' => data_list[3].to_i,
98
+ 'available_percent' => @trim_percent ? available_percent : "#{available_percent}%",
99
+ 'capacity' => data_list[4].to_i
100
+ }
101
+ disk_info
102
+ end
103
+ end
104
+
105
+ #-------------------------------------
106
+ # Replace / with _ in mounted_path.
107
+ #-------------------------------------
108
+ def replace_separator?(path)
109
+ @replace_separator ? path.gsub(%r{/}, '_') : path
110
+ end
111
+
112
+ #-------------------------------------
113
+ # Callback method for timer.
114
+ #-------------------------------------
115
+ def run_timer
116
+ diskfree.each do |result|
117
+ router.emit("#{@tag_prefix}.#{replace_separator?(@mounted_path)}", Fluent::Engine.now, result)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-diskfree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - h.nomura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.2.23
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.23
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.18.3
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.18.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: execute linux df command plugin for fluent.
104
+ email:
105
+ - h.nomura0504@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".github/ISSUE_TEMPLATE.md"
111
+ - ".github/PULL_REQUEST_TEMPLATE.md"
112
+ - ".github/workflows/rubocop.yml"
113
+ - ".gitignore"
114
+ - ".rspec"
115
+ - ".rubocop.yml"
116
+ - CHANGELOG.md
117
+ - CODE_OF_CONDUCT.md
118
+ - Dockerfile
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/console
124
+ - bin/setup
125
+ - docker-compose.yml
126
+ - fluent-plugin-diskfree.gemspec
127
+ - fluent.conf
128
+ - lib/fluent/plugin/in_diskfree.rb
129
+ homepage: https://github.com/nomunomu0504/fluent-plugin-diskfree
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ homepage_uri: https://github.com/nomunomu0504/fluent-plugin-diskfree
134
+ source_code_uri: https://github.com/nomunomu0504/fluent-plugin-diskfree
135
+ changelog_uri: https://github.com/nomunomu0504/fluent-plugin-diskfree/CHANGELOG.md
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.6.6
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.0.3
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: execute linux df command plugin for fluent.
155
+ test_files: []