giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.39k forks source link

[Windows] psutil.disk_io_counters shows virtual disks #2306

Open SnejPro opened 1 year ago

SnejPro commented 1 year ago

Summary

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.

giampaolo commented 1 year ago

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

SnejPro commented 1 year ago

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

Yes, correct.

giampaolo commented 1 year ago

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

SnejPro commented 1 year ago

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

Only disks with drive letters are displayed.

giampaolo commented 1 year ago

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

CarterLi commented 1 year ago

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)}
SnejPro commented 1 year ago

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?

CarterLi commented 1 year ago

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

SnejPro commented 1 year ago

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?

CarterLi commented 1 year ago

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

SnejPro commented 1 year ago

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.