Skip to content

Commit 6b07d09

Browse files
authored
[disk] handle multilines df output (#2733)
When moving the disk check outside of `checks/`, `_is_number` method was forgotten. This is now fixed and a test is added.
1 parent 4cba70a commit 6b07d09

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

checks.d/disk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def _flatten_devices(self, devices):
250250
for parts in devices:
251251
if len(parts) == 1:
252252
previous = parts[0]
253-
elif previous and self._is_number(parts[0]):
253+
elif previous is not None:
254254
# collate with previous line
255255
parts.insert(0, previous)
256256
previous = None
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Filesystem Type 1K-blocks Used Available Use% Mounted on
2+
/dev/sda3 ext4 93421512 70963180 17706052 81% /
3+
tmpfs tmpfs 32969616 0 32969616 0% /dev/shm
4+
/dev/sda1 ext4 512752 90460 395412 19% /boot
5+
10.1.5.223:/vil/cor
6+
nfs 1020054752 56080768 963973984 6% /cor

tests/checks/mock/test_disk.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ def test_no_psutil_freebsd(self, mock_df_output, mock_statvfs):
168168

169169
self.coverage_report()
170170

171+
@mock.patch('utils.subprocess_output.get_subprocess_output',
172+
return_value=(Fixtures.read_file('centos-df-Tk'), "", 0))
173+
@mock.patch('os.statvfs', return_value=MockInodesMetrics())
174+
def test_no_psutil_centos(self, mock_df_output, mock_statvfs):
175+
self.run_check({'instances': [{'use_mount': 'no',
176+
'excluded_filesystems': ['devfs', 'tmpfs'],
177+
'excluded_disks': ['/dev/sda1']}]},
178+
mocks={'_psutil': lambda: False})
179+
for device in ['/dev/sda3', '10.1.5.223:/vil/cor']:
180+
for metric, _ in self.GAUGES_VALUES.iteritems():
181+
self.assertMetric(metric, tags=[], device_name=device)
182+
183+
self.coverage_report()
184+
171185
def test_legacy_option(self):
172186
# First, let's check that it actually retrieves from the agent config
173187
self.load_check({'instances': [{}]}, agent_config={'use_mount': 'yes'})

0 commit comments

Comments
 (0)