监测mount的分区是可以的,请参考os模块的statvfs和fstatvfs函数以及statvfs模块:
target="_blank">http://docs.python.org/lib/os-file-dir.html#l2h-1610
target="_blank">http://docs.python.org/lib/os-fd-ops.html#l2h-1543
target="_blank">http://docs.python.org/lib/module-statvfs.html
下面是我写的一个取目录所在分区可用空间百分比的函数,可以参考:
from os import statvfs as pathstatvfs
import statvfs
from os.path import join as joinpath
from os.path import exists
def getAvailPercent(path):
if not exists(path):
return 0
vfs = pathstatvfs(path)
avail_percent = vfs[statvfs.F_BAVAIL] * 1.0 / vfs[statvfs.F_BLOCKS]
avail_percent = avail_percent * 100
return avail_percent
|