Home > Blockchain >  Get disk activity like in the windows task manager
Get disk activity like in the windows task manager

Time:12-09

I need to get the performance from the disk C:/ from my computer with python. I'm using psutil but there's no method to get this information. I want it exactly like in the task manager from windows but I can't get it : Disk performance in task manager

I tried different code found on stackoverflow but i don't get the right information. For example this one :

p = psutil.Process()
io_counters = p.io_counters()
disk_usage_process = io_counters[2]   io_counters[3] # read_bytes   write_bytes
disk_io_counter = psutil.disk_io_counters()
disk_total = disk_io_counter[2]   disk_io_counter[3] # read_bytes   write_bytes
print(disk_usage_process/disk_total * 100)
#Result 0.0004283707980337007

but i don't get the usage only the writing and the reading from the disk. i tried to put the code in a loop and wait 1 second but i doesn't change. If anyone have a solution maybe with another library.

Thanks !

CodePudding user response:

Yes, you can use the psutil module. Here is an example of how you can do this:

import psutil

# get disk usage information
disk_usage = psutil.disk_usage('C:/')

# print disk usage information
print('Total disk space:', disk_usage.total)
print('Used disk space:', disk_usage.used)
print('Free disk space:', disk_usage.free)
print('Percentage of disk space used:', disk_usage.percent) # i think this is the one u are looking for

CodePudding user response:

Yes, you can use the psutil module. Here is an example of how you can do this:

import psutil

# get disk usage information
disk_usage = psutil.disk_usage('C:/')

# print disk usage information
print('Total disk space:', disk_usage.total)
print('Used disk space:', disk_usage.used)
print('Free disk space:', disk_usage.free)
print('Percentage of disk space used:', disk_usage.percent)
  • Related