2

I am trying to set up some system monitoring. I want to calculate the percentage of time the disk is processing read or write requests. I am try to do this with psutil. My current solution looks like this:

readtime = (psutil.disk_io_counters().read_time / 1000) / 1000
writetime = (psutil.disk_io_counters().write_time / 1000) / 1000
busytime = readtime + writetime;

percentage = (busytime) / 60
print(percentage)

The double divide by 1000 is because I read somewhere that read_time returns nano seconds. My issue is this solution only ever return 4% even when I run a disk defragmentation and disk % is at 100 it returns 4%. I must be misunderstanding what read_time and write_time are used for. Does anyone know what I am doing wrong or have an alternative solution? I am currently testing this on Windows 10 environment.

Jeff Stapleton
  • 303
  • 3
  • 9
  • not sure if this is related, but i think the [psutil docs](https://pythonhosted.org/psutil/#psutil.disk_io_counters) state `read_time` is in *milliseconds* not nano seconds – chickity china chinese chicken Feb 01 '17 at 22:38
  • @downshift I thought so too but the numbers it was returning were too big. I found an [post](https://github.com/giampaolo/psutil/issues/700) that said it was actually nano seconds, which looked more correct. I maybe wrong though. – Jeff Stapleton Feb 01 '17 at 22:49

0 Answers0