in ambari-metrics-host-monitoring/src/main/python/core/host_info.py [0:0]
def get_combined_disk_usage(self):
combined_disk_total = 0
combined_disk_used = 0
combined_disk_free = 0
combined_disk_percent = 0
max_percent_usage = ('', 0)
partition_count = 0
devices = set()
for part in psutil.disk_partitions(all=False):
if os.name == 'nt':
if 'cdrom' in part.opts or part.fstype == '':
# skip cd-rom drives with no disk in it; they may raise
# ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang.
continue
pass
pass
try:
usage = psutil.disk_usage(part.mountpoint)
except Exception as e:
logger.debug('Failed to read disk_usage for a mountpoint : ' + str(e))
continue
if part.device in devices: # Skip devices already seen.
continue
devices.add(part.device)
combined_disk_total += usage.total if hasattr(usage, 'total') else 0
combined_disk_used += usage.used if hasattr(usage, 'used') else 0
combined_disk_free += usage.free if hasattr(usage, 'free') else 0
if hasattr(usage, 'percent'):
combined_disk_percent += usage.percent
partition_count += 1
if hasattr(usage, 'percent') and max_percent_usage[1] < int(usage.percent):
max_percent_usage = (part.mountpoint, usage.percent)
pass
pass
if partition_count > 0:
combined_disk_percent /= partition_count
return { "disk_total" : bytes2human(combined_disk_total),
"disk_used" : bytes2human(combined_disk_used),
"disk_free" : bytes2human(combined_disk_free),
"disk_percent" : combined_disk_percent
# todo: cannot send string
#"max_part_used" : max_percent_usage }
}