Class: Fluent::Plugin::SyscheckMountsInput
- Inherits:
-
Input
- Object
- Input
- Fluent::Plugin::SyscheckMountsInput
show all
- Defined in:
- lib/fluent/plugin/in_syscheck_mounts.rb
Defined Under Namespace
Classes: SysMount, SysMountStatus
Constant Summary
collapse
- NAME =
'syscheck_mounts'
- INTERVAL =
300
- TIMEOUT =
5
- ENABLED_FS_TYPES =
nil
- DISABLED_FS_TYPES =
%w[
binfmt_misc
bpf
cgroup
cgroup2
configfs
debugfs
devpts
devtmpfs
efivarfs
fusectl
hugetlbfs
mqueue
proc
pstore
rpc_pipefs
securityfs
squashfs
sysfs
tracefs
].freeze
- ENABLED_PATHS =
nil
- DISABLED_PATHS =
[].freeze
- ERROR_ONLY =
true
Instance Method Summary
collapse
Instance Method Details
#check ⇒ Object
95
96
97
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 95
def check
check_mounts
end
|
#check_mounts ⇒ Object
99
100
101
102
103
104
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 99
def check_mounts
system_mounts.each do |mount|
status = stat_async(mount)
emit_mount_status(mount, status)
end
end
|
80
81
82
83
84
85
86
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 80
def configure(conf)
super
raise Fluent::ConfigError, 'tag should not be empty' if tag.empty?
true
end
|
#disabled_fs_type?(fstype) ⇒ Boolean
124
125
126
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 124
def disabled_fs_type?(fstype)
disabled_fs_types&.include?(fstype)
end
|
#disabled_path?(path) ⇒ Boolean
134
135
136
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 134
def disabled_path?(path)
disabled_paths.any? { |path_pattern| path_pattern.match?(path) }
end
|
#emit_mount_status(mount, status) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 168
def emit_mount_status(mount, status)
log.debug "#{mount.mountpoint} (#{mount.fstype}): status - #{status}"
return if error_only && status.success?
router.emit(
tag,
Fluent::Engine.now,
mount.to_h.merge(status.to_h)
)
end
|
#enabled_fs_type?(fstype) ⇒ Boolean
118
119
120
121
122
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 118
def enabled_fs_type?(fstype)
return true unless enabled_fs_types
enabled_fs_types.include?(fstype)
end
|
#enabled_path?(path) ⇒ Boolean
128
129
130
131
132
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 128
def enabled_path?(path)
return true unless enabled_paths
enabled_paths.any? { |path_pattern| path_pattern.match?(path) }
end
|
#start ⇒ Object
88
89
90
91
92
93
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 88
def start
super
timer_execute(:check_first, 1, repeat: false, &method(:check)) if interval > 60
timer_execute(:check, interval, repeat: true, &method(:check))
end
|
#stat_async(mount) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 138
def stat_async(mount)
reader, writer = IO.pipe
pid = fork do
reader.close
File.stat(mount.mountpoint)
writer.puts 'ok'
rescue StandardError => e
writer.puts e.message
ensure
writer.close
exit! 0
end
writer.close
result = nil
begin
if reader.wait_readable(timeout)
result = reader.gets.strip
else
result = 'timeout'
Process.kill('KILL', pid) rescue nil
end
ensure
reader.close rescue nil
Process.wait(pid) rescue nil
end
SysMountStatus.new(result)
end
|
#system_mounts ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/fluent/plugin/in_syscheck_mounts.rb', line 106
def system_mounts
File.readlines('/proc/mounts').map do |mount_line|
device, mountpoint, fstype, _rest = mount_line.split
next unless enabled_fs_type?(fstype)
next if disabled_fs_type?(fstype)
next unless enabled_path?(mountpoint)
next if disabled_path?(mountpoint)
SysMount.new(device: device, mountpoint: mountpoint, fstype: fstype)
end.compact
end
|