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