61 lines
2.0 KiB
Python
Executable File
61 lines
2.0 KiB
Python
Executable File
#!/usr/bin/python2
|
|
|
|
""" 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["blocksize"] = fs.f_bsize #blocksize
|
|
part["total blocks"] = fs.f_blocks #total blocks
|
|
part["free blocks"] = fs.f_bavail #free blocks
|
|
break
|
|
|
|
mtab.close()
|
|
|
|
#adding partition to list
|
|
self.partitions.append(part)
|
|
|
|
#output
|
|
if __name__ == "__main__":
|
|
diskmoninstance = diskmon()
|
|
for partition in diskmoninstance.partitions:
|
|
print "device:\t\t" + str(partition["device"]) + \
|
|
"\nuuid:\t\t" + str(partition["uuid"])
|
|
if partition.has_key("mountpoint"):
|
|
print "mountpoint:\t" + str(partition["mountpoint"]) + \
|
|
"\nfilesystem:\t" + str(partition["filesystem"]) + \
|
|
"\nblocksize:\t" + str(partition["blocksize"]) + \
|
|
"\ntotal blocks:\t" + str(partition["total blocks"]) + \
|
|
"\nfree blocks:\t" + str(partition["free blocks"]) + "\n"
|
|
else:
|
|
print "\n"
|
|
|
|
|
|
|
|
#end of file
|