did a rewrite of diskusage in disk_mon.py
This commit is contained in:
parent
62fc2fb2f1
commit
bc9d4951d1
|
@ -0,0 +1,60 @@
|
|||
#!/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)
|
||||
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)
|
||||
|
||||
#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])
|
||||
break
|
||||
self.mtab.close()
|
||||
|
||||
#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
|
||||
|
||||
#adding partition to list
|
||||
self.partitions.append(self.part)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#output
|
||||
if __name__ == "__main__":
|
||||
diskmoninstance = diskmon()
|
||||
diskmoninstance.gather()
|
||||
#print diskmoninstance.partitions
|
||||
for partition in diskmoninstance.partitions:
|
||||
print "device: " + str(partition[0]) + "\nuuid: " + str(partition[1]) + "\nmountpoint: " + str(partition[2]) + "\nfilesystem: " + str(partition[3]) + "\nblocksize: " + str(partition[4]) + "\ntotal blocks: " + str(partition[5]) + "\nfree blocks: " + str(partition[6]) + "\n\n"
|
||||
|
||||
|
||||
#end of file
|
Reference in New Issue