Skip to content

Commit 79b1843

Browse files
committed
[disk] Add option to exclude pseudo file systems
Improve log messages
1 parent f9fac0c commit 79b1843

4 files changed

Lines changed: 125 additions & 4 deletions

File tree

disk/assets/configuration/spec.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,42 @@ files:
4242
start matching from the beginning and therefore to match anywhere you
4343
must prepend `.*`. For exact matches append `$`.
4444
45+
Some Linux kernel pseudo file systems can be excluded by enabling the
46+
`exclude_pseudofs` option.
47+
4548
When conflicts arise, this will override `file_system_whitelist`.
4649
value:
4750
example:
4851
- tmpfs$
4952
- rootfs$
5053
- autofs$
54+
- overlay$
5155
type: array
5256
items:
5357
type: string
58+
- name: exclude_pseudo_file_systems
59+
description: |
60+
Instruct the check to not collect from some common pseudo file systems.
61+
Works on Linux only.
62+
63+
The pseudo file systems excluded with this option are:
64+
- binfmt_misc
65+
- configfs
66+
- debugfs
67+
- devtmpfs
68+
- overlay
69+
- proc
70+
- rootfs
71+
- securityfs
72+
- sysfs
73+
- tmpfs
74+
- tracefs
75+
76+
You may cease to ignore a specific pseudo file system by adding it to
77+
the `file_system_whitelist`.
78+
value:
79+
example: true
80+
type: boolean
5481
- name: device_whitelist
5582
description: |
5683
Instruct the check to only collect from matching devices.

disk/datadog_checks/disk/data/conf.yaml.default

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,38 @@ instances:
4444
## start matching from the beginning and therefore to match anywhere you
4545
## must prepend `.*`. For exact matches append `$`.
4646
##
47+
## Some Linux kernel pseudo file systems can be excluded by enabling the
48+
## `exclude_pseudofs` option.
49+
##
4750
## When conflicts arise, this will override `file_system_whitelist`.
4851
#
4952
# file_system_blacklist:
5053
# - tmpfs$
5154
# - rootfs$
5255
# - autofs$
56+
# - overlay$
57+
58+
## @param exclude_pseudo_file_systems - boolean - optional - default: true
59+
## Instruct the check to not collect from some common pseudo file systems.
60+
## Works on Linux only.
61+
##
62+
## The pseudo file systems excluded with this option are:
63+
## - binfmt_misc
64+
## - configfs
65+
## - debugfs
66+
## - devtmpfs
67+
## - overlay
68+
## - proc
69+
## - rootfs
70+
## - securityfs
71+
## - sysfs
72+
## - tmpfs
73+
## - tracefs
74+
##
75+
## You may cease to ignore a specific pseudo file system by adding it to
76+
## the `file_system_whitelist`.
77+
#
78+
# exclude_pseudo_file_systems: true
5379

5480
## @param device_whitelist - list of strings - optional
5581
## Instruct the check to only collect from matching devices.

disk/datadog_checks/disk/disk.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,42 @@
2020
# See: https://github.com/DataDog/integrations-core/pull/1109#discussion_r167133580
2121
IGNORE_CASE = re.I
2222

23+
KNOWN_PSEUDO_FILE_SYSTEMS = set()
24+
2325
def _base_device_name(device):
2426
return device.strip('\\').lower()
2527

2628

29+
elif platform.system() == "Linux":
30+
IGNORE_CASE = 0
31+
32+
# Remember to update the configuration specification
33+
# if modifying the list of pseudo file systems.
34+
KNOWN_PSEUDO_FILE_SYSTEMS = set(
35+
[
36+
'binfmt_msc',
37+
'configfs',
38+
'debugfs',
39+
'devtmpfs',
40+
'overlay',
41+
'proc',
42+
'rootfs',
43+
'securityfs',
44+
'sysfs',
45+
'tmpfs',
46+
'tracefs',
47+
]
48+
)
49+
50+
def _base_device_name(device):
51+
return os.path.basename(device)
52+
53+
2754
else:
2855
IGNORE_CASE = 0
2956

57+
KNOWN_PSEUDO_FILE_SYSTEMS = set()
58+
3059
def _base_device_name(device):
3160
return os.path.basename(device)
3261

@@ -47,6 +76,8 @@ def __init__(self, name, init_config, instances):
4776
self._all_partitions = is_affirmative(instance.get('all_partitions', False))
4877
self._file_system_whitelist = instance.get('file_system_whitelist', [])
4978
self._file_system_blacklist = instance.get('file_system_blacklist', [])
79+
# FIXME (8.X): Enable pseudo file systems exclusion by default
80+
self._exclude_pseudo_file_systems = instance.get('exclude_pseudo_file_systems', False)
5081
self._device_whitelist = instance.get('device_whitelist', [])
5182
self._device_blacklist = instance.get('device_blacklist', [])
5283
self._mount_point_whitelist = instance.get('mount_point_whitelist', [])
@@ -88,7 +119,21 @@ def check(self, instance):
88119
)
89120
continue
90121
except Exception as e:
91-
self.log.warning('Unable to get disk metrics for %s: %s', part.mountpoint, e)
122+
if not self._exclude_pseudo_file_systems and part.fstype in KNOWN_PSEUDO_FILE_SYSTEMS:
123+
self.log.warning(
124+
u'Unable to get disk metrics for %s with pseudo file system %s: %s. '
125+
u'Enable `exclude_pseudo_file_systems` to ignore common pseudo file systems.',
126+
part.mountpoint,
127+
part.fstype,
128+
e,
129+
)
130+
else:
131+
self.log.warning(
132+
u'Unable to get disk metrics for %s: %s. '
133+
u'You can exclude this mountpoint in the settings if it is invalid.',
134+
part.mountpoint,
135+
e,
136+
)
92137
continue
93138

94139
# Exclude disks with size less than min_disk_size
@@ -147,7 +192,6 @@ def _exclude_disk(self, device, file_system, mount_point):
147192
"""
148193
Return True for disks we don't want or that match regex in the config file
149194
"""
150-
self.log.debug('_exclude_disk: %s, %s, %s', device, file_system, mount_point)
151195

152196
if not device or device == 'none':
153197
device = None
@@ -190,6 +234,14 @@ def _file_system_blacklisted(self, file_system):
190234
if self._file_system_blacklist is None:
191235
return False
192236

237+
# Check if it is a known pseudo file system
238+
if (
239+
self._exclude_pseudo_file_systems
240+
and file_system in KNOWN_PSEUDO_FILE_SYSTEMS
241+
and not self._file_system_whitelisted(file_system)
242+
):
243+
return True
244+
193245
return not not self._file_system_blacklist.match(file_system)
194246

195247
def _device_whitelisted(self, device):
@@ -245,7 +297,12 @@ def _collect_inodes_metrics(self, mountpoint):
245297
)
246298
return metrics
247299
except Exception as e:
248-
self.log.warning('Unable to get disk metrics for %s: %s', mountpoint, e)
300+
self.log.warning(
301+
u'Unable to get disk metrics for %s: %s. '
302+
u'You can exclude this mountpoint in the settings if it is invalid.',
303+
mountpoint,
304+
e,
305+
)
249306
return metrics
250307

251308
if inodes.f_files != 0:

disk/tests/test_filter.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from datadog_checks.disk.disk import IGNORE_CASE, Disk
88

99
from .mocks import MockPart
10-
from .utils import assert_regex_equal, requires_windows
10+
from .utils import assert_regex_equal, requires_linux, requires_windows
1111

1212

1313
def test_default_casing():
@@ -104,6 +104,17 @@ def test_file_system_whitelist_blacklist():
104104
assert c.exclude_disk(MockPart(fstype='NTFS')) is True
105105

106106

107+
@requires_linux
108+
def test_exclude_pseudo_file_system():
109+
instance = {'file_system_whitelist': ['tracefs$'], 'exclude_pseudo_file_systems': True}
110+
c = Disk('disk', {}, [instance])
111+
112+
assert c.exclude_disk(MockPart(fstype='debugfs')) is True
113+
assert c.exclude_disk(MockPart(fstype='tempfs')) is True
114+
assert c.exclude_disk(MockPart(fstype='ext4')) is False
115+
assert c.exclude_disk(MockPart(fstype='tracefs')) is False
116+
117+
107118
def test_device_whitelist():
108119
instance = {'device_whitelist': ['/dev/sda[1-3]', 'c:']}
109120
c = Disk('disk', {}, [instance])

0 commit comments

Comments
 (0)