46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
""" disk monitor """
|
|
|
|
class diskmon(object):
|
|
"""collect information about local partitions"""
|
|
|
|
def __init__(self):
|
|
self.update()
|
|
|
|
def update(self):
|
|
"""run collection of data"""
|
|
|
|
import os
|
|
|
|
self.partitions = []
|
|
uuids = os.listdir("/dev/disk/by-uuid")
|
|
for uuid in uuids:
|
|
part = {}
|
|
part["device"] = str("/dev/" + os.readlink("/dev/disk/by-uuid/" + uuid)[6:])
|
|
part["uuid"] = uuid
|
|
|
|
#getting mountpoint for partition from mtab
|
|
mtab = open("/etc/mtab", "r")
|
|
#for line in
|
|
for line in mtab:
|
|
if part["device"] in line:
|
|
part["mountpoint"] = line.split()[1]
|
|
part["filesystem"] = line.split()[2]
|
|
#getting block infos
|
|
if os.path.ismount(part["mountpoint"]):
|
|
fs = os.statvfs(part["mountpoint"])
|
|
part["mounted"] = "1" #mounted flag
|
|
part["blocksize"] = fs.f_bsize #blocksize
|
|
part["total blocks"] = fs.f_blocks #total blocks
|
|
part["free blocks"] = fs.f_bavail #free blocks
|
|
part["used blocks"] = part["total blocks"] - part["free blocks"]
|
|
part["files"] = fs.f_files #total files
|
|
break
|
|
|
|
mtab.close()
|
|
|
|
#adding partition to list
|
|
self.partitions.append(part)
|
|
|
|
|
|
#end of file
|