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"""
|
"""gather the actual information"""
|
||||||
|
|
||||||
self.partitions = [] #information about all partitions (list of lists)
|
self.partitions = [] #information about all partitions (list of lists)
|
||||||
self.part = [] #information about one partition
|
part = [] #information about one partition
|
||||||
self.uuids = os.listdir("/dev/disk/by-uuid") #folder contains symlinks to the actual disk devices
|
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
|
for uuid in 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:])
|
part.append("/dev/" + os.readlink("/dev/disk/by-uuid/" + uuid)[6:])
|
||||||
self.part.append(self.uuid)
|
part.append(uuid)
|
||||||
|
|
||||||
#getting mountpoint for partition from mtab
|
#getting mountpoint for partition from mtab
|
||||||
self.mtab = open("/etc/mtab", "r")
|
mtab = open("/etc/mtab", "r")
|
||||||
for self.line in self.mtab.readlines():
|
#for line in
|
||||||
if self.part[0] in self.line:
|
for line in mtab:
|
||||||
self.part.append(self.line.split()[1])
|
if part[0] in line:
|
||||||
self.part.append(self.line.split()[2])
|
part.append(line.split()[1])
|
||||||
|
part.append(line.split()[2])
|
||||||
#getting block infos
|
#getting block infos
|
||||||
if os.path.ismount(self.part[2]):
|
if os.path.ismount(part[2]):
|
||||||
self.fs = os.statvfs(self.part[2])
|
fs = os.statvfs(part[2])
|
||||||
self.part.append(self.fs.f_bsize) #blocksize
|
part.append(fs.f_bsize) #blocksize
|
||||||
self.part.append(self.fs.f_blocks) #total blocks
|
part.append(fs.f_blocks) #total blocks
|
||||||
self.part.append(self.fs.f_bavail) #free blocks
|
part.append(fs.f_bavail) #free blocks
|
||||||
|
break
|
||||||
|
|
||||||
try: self.part[2]
|
mtab.close()
|
||||||
except IndexError:
|
|
||||||
for i in range(4):
|
|
||||||
self.part.append("not mounted")
|
|
||||||
|
|
||||||
self.mtab.close()
|
|
||||||
|
|
||||||
#adding partition to list
|
#adding partition to list
|
||||||
self.partitions.append(self.part)
|
self.partitions.append(part)
|
||||||
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
|
@ -55,8 +52,10 @@ if __name__ == "__main__":
|
||||||
diskmoninstance.gather()
|
diskmoninstance.gather()
|
||||||
#print diskmoninstance.partitions
|
#print diskmoninstance.partitions
|
||||||
for partition in 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