Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[disk] another timeout on disk usage #2823

Merged
merged 1 commit into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion checks.d/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,19 @@ def _collect_part_metrics(self, part, usage):

def _collect_inodes_metrics(self, mountpoint):
metrics = {}
inodes = os.statvfs(mountpoint)
# we need to timeout this, too.
try:
inodes = timeout(5)(os.statvfs)(mountpoint)
except TimeoutException:
self.log.warn(
u"Timeout while retrieving the disk usage of `%s` mountpoint. Skipping...",
mountpoint
)
return metrics
except Exception as e:
self.log.warn("Unable to get disk metrics for %s: %s", mountpoint, e)
return metrics

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe returning an empty dictionary would cause a KeyError exception here.

Alternatively we could catch the exception within the collect_metrics_psutil method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yannmh I think you're looking at the wrong thing. These are the system.fs.inodes.* metrics. They're not referenced anywhere else.

if inodes.f_files != 0:
total = inodes.f_files
free = inodes.f_ffree
Expand Down
14 changes: 13 additions & 1 deletion tests/checks/mock/test_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

DEFAULT_DEVICE_NAME = '/dev/sda1'


class MockPart(object):
def __init__(self, device=DEFAULT_DEVICE_NAME, fstype='ext4',
mountpoint='/'):
Expand Down Expand Up @@ -114,6 +113,8 @@ def test_device_exclusion_logic_no_name(self):
def test_psutil(self, mock_partitions, mock_usage, mock_inodes):
# Mocking
mock_usage.__name__ = "foo"
mock_inodes.__name__ = "foo"
mock_partitions.__name__ = "foo"

# Run check
for tag_by in ['yes', 'no']:
Expand All @@ -134,6 +135,8 @@ def test_psutil(self, mock_partitions, mock_usage, mock_inodes):
def test_use_mount(self, mock_partitions, mock_usage, mock_inodes):
# Mocking
mock_usage.__name__ = "foo"
mock_inodes.__name__ = "foo"
mock_partitions.__name__ = "foo"

# Run check
self.run_check({'instances': [{'use_mount': 'yes'}]})
Expand All @@ -149,6 +152,9 @@ def test_use_mount(self, mock_partitions, mock_usage, mock_inodes):
return_value=(Fixtures.read_file('debian-df-Tk'), "", 0))
@mock.patch('os.statvfs', return_value=MockInodesMetrics())
def test_no_psutil_debian(self, mock_df_output, mock_statvfs):
mock_statvfs.__name__ = "foo"
mock_df_output.__name__ = "foo"

self.run_check({'instances': [{'use_mount': 'no',
'excluded_filesystems': ['tmpfs']}]},
mocks={'_psutil': lambda: False})
Expand All @@ -165,6 +171,9 @@ def test_no_psutil_debian(self, mock_df_output, mock_statvfs):
return_value=(Fixtures.read_file('freebsd-df-Tk'), "", 0))
@mock.patch('os.statvfs', return_value=MockInodesMetrics())
def test_no_psutil_freebsd(self, mock_df_output, mock_statvfs):
mock_statvfs.__name__ = "foo"
mock_df_output.__name__ = "foo"

self.run_check({'instances': [{'use_mount': 'no',
'excluded_filesystems': ['devfs'],
'excluded_disk_re': 'zroot/.+'}]},
Expand All @@ -180,6 +189,9 @@ def test_no_psutil_freebsd(self, mock_df_output, mock_statvfs):
return_value=(Fixtures.read_file('centos-df-Tk'), "", 0))
@mock.patch('os.statvfs', return_value=MockInodesMetrics())
def test_no_psutil_centos(self, mock_df_output, mock_statvfs):
mock_statvfs.__name__ = "foo"
mock_df_output.__name__ = "foo"

self.run_check({'instances': [{'use_mount': 'no',
'excluded_filesystems': ['devfs', 'tmpfs'],
'excluded_disks': ['/dev/sda1']}]},
Expand Down