psutil icon indicating copy to clipboard operation
psutil copied to clipboard

[Windows] psutil.disk_io_counters shows virtual disks

Open SnejPro opened this issue 2 years ago • 11 comments

Summary

  • OS: Windows Server 2022
  • Architecture: { 64bit }
  • Psutil version: 5.9.5
  • Python version: 3.11.5
  • Type: disk-io

Description

I use psutil to monitor several Windows servers. Two of these servers are Windows Terminal Servers with user profile disks. Users therefore "take their data" with them when they log on to one of the terminal servers.

grafik

Unfortunately, psutil gets the performance data from these virtual disks and you can't distinguish them from "real" physical disk, because they are labled as "PhysicalDriveX"

>>> psutil.disk_io_counters(True)
{'PhysicalDrive0': sdiskio(read_count=171541, write_count=87278, read_bytes=7474899968, write_bytes=3955401216, read_time=38, write_time=61), 'PhysicalDrive1': sdiskio(read_count=27264, write_count=41933, read_bytes=333447168, write_bytes=475046400, read_time=18, write_time=30), 'PhysicalDrive2': sdiskio(read_count=16980, write_count=14100, read_bytes=89072128, write_bytes=143016448, read_time=6, write_time=12)} 

It would therefore be good if psutil did not monitor these disks or if they could be excluded.

SnejPro avatar Sep 24 '23 17:09 SnejPro

So these kind of disks are listed by psutil but you would like a way to filter them?

giampaolo avatar Sep 24 '23 20:09 giampaolo

So these kind of disks are listed by psutil but you would like a way to filter them?

Yes, correct.

SnejPro avatar Sep 24 '23 20:09 SnejPro

What's the output of psutil.disk_partitions()?

giampaolo avatar Sep 24 '23 20:09 giampaolo

What's the output of psutil.disk_partitions()?

Only disks with drive letters are displayed.

SnejPro avatar Sep 24 '23 21:09 SnejPro

Actually, please post the output of psutil.disk_partitions(all=True)

giampaolo avatar Sep 24 '23 21:09 giampaolo

Same issue here.

In [10]: psutil.disk_partitions(all=True)
Out[10]:
[sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260),
 sdiskpart(device='D:\\', mountpoint='D:\\', fstype='Btrfs', opts='rw,fixed', maxfile=255, maxpath=260),
 sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260)]

In [11]: psutil.disk_io_counters(True)
Out[11]:
{'PhysicalDrive0': sdiskio(read_count=673391, write_count=558429, read_bytes=29181166592, write_bytes=38308701696, read_time=302, write_time=172),
 'PhysicalDrive1': sdiskio(read_count=2471, write_count=238, read_bytes=736361472, write_bytes=1359872, read_time=21, write_time=0)}

CarterLi avatar Sep 25 '23 14:09 CarterLi

Same issue here.

In [10]: psutil.disk_partitions(all=True)
Out[10]:
[sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260),
 sdiskpart(device='D:\\', mountpoint='D:\\', fstype='Btrfs', opts='rw,fixed', maxfile=255, maxpath=260),
 sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260)]

In [11]: psutil.disk_io_counters(True)
Out[11]:
{'PhysicalDrive0': sdiskio(read_count=673391, write_count=558429, read_bytes=29181166592, write_bytes=38308701696, read_time=302, write_time=172),
 'PhysicalDrive1': sdiskio(read_count=2471, write_count=238, read_bytes=736361472, write_bytes=1359872, read_time=21, write_time=0)}

C:, D:\ and E:\ are on one physcial drive?

SnejPro avatar Sep 25 '23 14:09 SnejPro

C: and D: are on the internal SSD. E: is on my USB mobile hard disk.

CarterLi avatar Sep 25 '23 15:09 CarterLi

C: and D: are on the internal SSD. E: is on my USB mobile hard disk.

but then PhysicalDrive1 is the USB hard disk, not a virtual hard disk?

SnejPro avatar Sep 25 '23 15:09 SnejPro

I don't know. Why can't it be D:?

CarterLi avatar Sep 25 '23 15:09 CarterLi

Actually, please post the output of psutil.disk_partitions(all=True)

At this time 3 users with virtual user disks were logged onto the server:

>>> psutil.disk_io_counters(True)
{
'PhysicalDrive0': sdiskio(read_count=245371, write_count=601508, read_bytes=11506310656, write_bytes=11949560320, read_time=53, write_time=268),
'PhysicalDrive1': sdiskio(read_count=44750, write_count=213319, read_bytes=476360192, write_bytes=3449132032, read_time=24, write_time=143),
'PhysicalDrive2': sdiskio(read_count=16781, write_count=19941, read_bytes=92403200, write_bytes=151933440, read_time=6, write_time=7),
'PhysicalDrive4': sdiskio(read_count=33197, write_count=101242, read_bytes=354310656, write_bytes=2948272640, read_time=16, write_time=73)
}
>>> psutil.disk_partitions(all=True)
[
sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260),
sdiskpart(device='D:\\', mountpoint='D:\\', fstype='', opts='cdrom', maxfile=255, maxpath=260),
sdiskpart(device='G:\\', mountpoint='G:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='H:\\', mountpoint='H:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='I:\\', mountpoint='I:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='J:\\', mountpoint='J:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='K:\\', mountpoint='K:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='L:\\', mountpoint='L:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='Q:\\', mountpoint='Q:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='R:\\', mountpoint='R:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260),
sdiskpart(device='Z:\\', mountpoint='Z:\\', fstype='NTFS', opts='rw,remote', maxfile=255, maxpath=260)
]

disk_partitions shows only C:, not the virtual disks, the cdrom drive is empty and all other sdiskparts are remote shares.

SnejPro avatar Sep 25 '23 15:09 SnejPro