nikademus79 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Provide function to get system disk partitions #174

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In issue 172 we added psutil.disk_usage() function which provides disk usage 
statistics starting from a given path.
What's missing is a facility to get all system partitions (mount points) to be 
used in conjunction with psutil.disk_usage() which would provide all the pieces 
to perform a complete monitoring of all disks instealled on the system.

What I have in mind:

>>> psutil.disk_partitions()
[partition(device='/dev/sda3', mountpoint='/', fstype='ext4')
partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')
partition(device='/dev/sdb1', mountpoint='/media/1CA0-065B', fstype='vfat')
partition(device='/dev/sda6', mountpoint='/media/Dati', fstype='fuseblk')]

The way I see it, disk_partitions() should return information about *mounted* 
physical devices only, and hence behave more like "df" rather than "fdisk -l".
Also, "df" reports mount points which doesn't refer to actual physical devices, 
such as "/dev/shm" ( 
http://www.cyberciti.biz/tips/what-is-devshm-and-its-practical-usage.html ), 
"/var/run" and "/var/lock". 
IMO, we should ignore them.

Attached is a draft for Linux.
Still have to look into other implementations.

Original issue reported on code.google.com by g.rodola on 15 Jun 2011 at 9:07

Attachments:

GoogleCodeExporter commented 8 years ago
Implemented on Linux in r1026.
I provided an "all" optional argument defaulting to False to filter for 
physical devices only.

>>> psutil.disk_partitions()
partition(device='/dev/sda3', mountpoint='/', fstype='ext4')
partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')
partition(device='/dev/sdb1', mountpoint='/media/1CA0-065B', fstype='vfat')
partition(device='/dev/sda6', mountpoint='/media/Dati', fstype='fuseblk')
>>>

>>> psutil.disk_partitions(all=True)
partition(device='/dev/sda3', mountpoint='/', fstype='ext4')
partition(device='proc', mountpoint='/proc', fstype='proc')
partition(device='', mountpoint='/sys', fstype='sysfs')
partition(device='fusectl', mountpoint='/sys/fs/fuse/connections', 
fstype='fusectl')
partition(device='', mountpoint='/sys/kernel/debug', fstype='debugfs')
partition(device='', mountpoint='/sys/kernel/security', fstype='securityfs')
partition(device='', mountpoint='/dev', fstype='devtmpfs')
partition(device='', mountpoint='/dev/pts', fstype='devpts')
partition(device='', mountpoint='/dev/shm', fstype='tmpfs')
partition(device='', mountpoint='/var/run', fstype='tmpfs')
partition(device='', mountpoint='/var/lock', fstype='tmpfs')
partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')
partition(device='binfmt_misc', mountpoint='/proc/sys/fs/binfmt_misc', 
fstype='binfmt_misc')
partition(device='gvfs-fuse-daemon', mountpoint='/home/giampaolo/.gvfs', 
fstype='fuse.gvfs-fuse-daemon')
partition(device='/dev/sdb1', mountpoint='/media/1CA0-065B', fstype='vfat')
partition(device='/dev/sda6', mountpoint='/media/Dati', fstype='fuseblk')

Original comment by g.rodola on 15 Jun 2011 at 10:00

GoogleCodeExporter commented 8 years ago
FreeBSD implementation added as r1027.

Original comment by g.rodola on 16 Jun 2011 at 10:07

GoogleCodeExporter commented 8 years ago
Implemented on Windows in r1030.

Original comment by g.rodola on 17 Jun 2011 at 6:04

GoogleCodeExporter commented 8 years ago
Attached is a patch for OS X support.  It is identical to BSD support but I 
couldn't find a good way to share code between the BSD and OS X 
implementations.  That being said, I copied the approach for BSD to implement 
OS X support.  If you know a better way to do this so that OS X uses the BSD 
sources for this, since OS X is a BSD derivative, feel free to just commit your 
version.

Original comment by jcscoob...@gmail.com on 27 Jun 2011 at 4:46

Attachments:

GoogleCodeExporter commented 8 years ago
Added in r1047.
As for now I can't think of a smart way to share the same code between OSX and 
FreeBSD. I'll think about it later. Closing out as FixedInSvn for now.

Original comment by g.rodola on 27 Jun 2011 at 4:56

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 27 Jun 2011 at 5:52

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 8 Jul 2011 at 7:07

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Updated csets after the SVN -> Mercurial migration:
r1026 == revision 5e77d0b5125a
r1027 == revision d05c75bf4288
r1030 == revision a566c8a5fbf6
r1047 == revision 186496a8bd0f

Original comment by g.rodola on 2 Mar 2013 at 12:01