test commit
This commit is contained in:
parent
c66f250679
commit
ef8c72ba78
45
disk_mon.py
45
disk_mon.py
|
@ -19,34 +19,31 @@ class diskmon(object):
|
|||
"""gather the actual information"""
|
||||
|
||||
self.partitions = [] #information about all partitions (list of lists)
|
||||
self.part = [] #information about one partition
|
||||
self.uuids = os.listdir("/dev/disk/by-uuid") #folder contains symlinks to the actual disk devices
|
||||
for self.uuid in self.uuids: #write /dev/names as keys and uuids as values in the dictionary
|
||||
self.part.append("/dev/" + os.readlink("/dev/disk/by-uuid/" + self.uuid)[6:])
|
||||
self.part.append(self.uuid)
|
||||
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
|
||||
self.mtab = open("/etc/mtab", "r")
|
||||
for self.line in self.mtab.readlines():
|
||||
if self.part[0] in self.line:
|
||||
self.part.append(self.line.split()[1])
|
||||
self.part.append(self.line.split()[2])
|
||||
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(self.part[2]):
|
||||
self.fs = os.statvfs(self.part[2])
|
||||
self.part.append(self.fs.f_bsize) #blocksize
|
||||
self.part.append(self.fs.f_blocks) #total blocks
|
||||
self.part.append(self.fs.f_bavail) #free blocks
|
||||
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
|
||||
|
||||
try: self.part[2]
|
||||
except IndexError:
|
||||
for i in range(4):
|
||||
self.part.append("not mounted")
|
||||
|
||||
self.mtab.close()
|
||||
mtab.close()
|
||||
|
||||
#adding partition to list
|
||||
self.partitions.append(self.part)
|
||||
self.partitions.append(part)
|
||||
|
||||
|
||||
#output
|
||||
|
@ -55,8 +52,10 @@ if __name__ == "__main__":
|
|||
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"
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
|
Reference in New Issue