def get_disk_usage(self): disk_usage_info = {} partition = subprocess.Popen("df -PT -t ext2 -t ext3 -t ext4 -t xfs", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) for line in partition.stdout: if 'Filesystem' in line: continue partition_name = line.rsplit()[0] partition_type = line.rsplit()[1] partition_space_used_1k = line.rsplit()[3] partition_space_available_1k = line.rsplit()[4] disk_usage_stat = DiskPartitionUsageStats() try: disk_usage_stat.partition_type = str(partition_type) disk_usage_stat.__key = str(partition_name) disk_usage_stat.partition_space_used_1k = \ int(partition_space_used_1k) disk_usage_stat.partition_space_available_1k = \ int(partition_space_available_1k) total_disk_space = \ disk_usage_stat.partition_space_used_1k + \ disk_usage_stat.partition_space_available_1k disk_usage_stat.percentage_partition_space_used = \ int(round((float(disk_usage_stat.partition_space_used_1k)/ \ float(total_disk_space))*100)) except ValueError: self.msg_log('Failed to get local disk space usage', SandeshLevel.SYS_ERR) else: disk_usage_info[partition_name] = disk_usage_stat return disk_usage_info
def get_disk_usage(self): disk_usage_info = {} partition = subprocess.Popen( "df -PT -t ext2 -t ext3 -t ext4 -t xfs", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) for line in partition.stdout: if 'Filesystem' in line: continue partition_name = line.rsplit()[0] partition_type = line.rsplit()[1] partition_space_used_1k = line.rsplit()[3] partition_space_available_1k = line.rsplit()[4] disk_usage_stat = DiskPartitionUsageStats() try: disk_usage_stat.partition_type = str(partition_type) disk_usage_stat.__key = str(partition_name) disk_usage_stat.partition_space_used_1k = \ int(partition_space_used_1k) disk_usage_stat.partition_space_available_1k = \ int(partition_space_available_1k) total_disk_space = \ disk_usage_stat.partition_space_used_1k + \ disk_usage_stat.partition_space_available_1k disk_usage_stat.percentage_partition_space_used = \ int(round((float(disk_usage_stat.partition_space_used_1k)/ \ float(total_disk_space))*100)) except ValueError: self.msg_log('Failed to get local disk space usage', SandeshLevel.SYS_ERR) else: disk_usage_info[partition_name] = disk_usage_stat return disk_usage_info