63 lines
1.9 KiB
Python
Executable File
63 lines
1.9 KiB
Python
Executable File
#!/usr/bin/python2
|
|
|
|
#
|
|
# disk monitor
|
|
#
|
|
|
|
#imports
|
|
import os
|
|
|
|
|
|
class diskmon(object):
|
|
"""collect information about local partitions"""
|
|
|
|
#constructor
|
|
def __init__(self):
|
|
pass
|
|
|
|
def gather(self):
|
|
"""gather the actual information"""
|
|
|
|
self.partitions = [] #information about all partitions (list of lists)
|
|
part = [] #information about one partition
|
|
uuids = os.listdir("/dev/disk/by-uuid") #folder contains symlinks to the actual disk devices
|
|
for uuid in uuids: #write /dev/names as keys and uuids as values in the dictionary
|
|
part.append("/dev/" + os.readlink("/dev/disk/by-uuid/" + uuid)[6:])
|
|
part.append(uuid)
|
|
|
|
#getting mountpoint for partition from mtab
|
|
mtab = open("/etc/mtab", "r")
|
|
#for line in
|
|
for line in mtab:
|
|
if part[0] in line:
|
|
part.append(line.split()[1])
|
|
part.append(line.split()[2])
|
|
#getting block infos
|
|
if os.path.ismount(part[2]):
|
|
fs = os.statvfs(part[2])
|
|
part.append(fs.f_bsize) #blocksize
|
|
part.append(fs.f_blocks) #total blocks
|
|
part.append(fs.f_bavail) #free blocks
|
|
break
|
|
|
|
mtab.close()
|
|
|
|
#adding partition to list
|
|
self.partitions.append(part)
|
|
|
|
|
|
#output
|
|
if __name__ == "__main__":
|
|
diskmoninstance = diskmon()
|
|
diskmoninstance.gather()
|
|
#print diskmoninstance.partitions
|
|
for partition in diskmoninstance.partitions:
|
|
#print "device:\t\t" + str(partition[0]) + "\nuuid:\t\t" + str(partition[1]) + "\nmountpoint:\t" + str(partition[2]) + "\nfilesystem:\t" + str(partition[3]) + "\nblocksize:\t" + str(partition[4]) + "\ntotal blocks:\t" + str(partition[5]) + "\nfree blocks:\t" + str(partition[6]) + "\n"
|
|
|
|
for item in partition:
|
|
print item
|
|
|
|
|
|
|
|
#end of file
|