Skip to content

Commit

Permalink
Merge pull request #1784 from DataDog/zeller/disk-check
Browse files Browse the repository at this point in the history
Recalculate disk.in_use to make consistent with df's Use% metric
  • Loading branch information
Remi Hakim committed Jul 27, 2015
2 parents aef931c + 484f052 commit 28a1595
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion checks.d/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ def collect_metrics_psutil(self):
tags = [part.fstype] if self._tag_by_filesystem else []
device_name = part.mountpoint if self._use_mount else part.device

# Note: psutil (0.3.0 to at least 3.1.1) calculates in_use as (used / total)
# The problem here is that total includes reserved space the user
# doesn't have access to. This causes psutil to calculate a misleadng
# percentage for in_use; a lower percentage than df shows.

# Calculate in_use w/o reserved space; consistent w/ df's Use% metric.
pmets = self._collect_part_metrics(part, disk_usage)
used = 'system.disk.used'
free = 'system.disk.free'
pmets['system.disk.in_use'] = pmets[used] / (pmets[used] + pmets[free])

# legacy check names c: vs psutil name C:\\
if Platform.is_win32():
device_name = device_name.strip('\\').lower()
for metric_name, metric_value in self._collect_part_metrics(part, disk_usage).iteritems():
for metric_name, metric_value in pmets.iteritems():
self.gauge(metric_name, metric_value,
tags=tags, device_name=device_name)
# And finally, latency metrics, a legacy gift from the old Windows Check
Expand Down

0 comments on commit 28a1595

Please sign in to comment.