some changes in monitor/disk_display.py
This commit is contained in:
parent
40b64def61
commit
b5e6e2cfd7
|
@ -5,36 +5,37 @@
|
|||
import disk
|
||||
|
||||
def bytes2human(bytes):
|
||||
units = ["B", "KB", "MB", "GB", "TB", "PB", "EB"]
|
||||
units = ["", "K", "M", "G", "T", "P", "E"]
|
||||
counter = 0
|
||||
while bytes > 1024:
|
||||
bytes = bytes / 1024
|
||||
counter += 1
|
||||
human = [bytes, units[counter]]
|
||||
return human
|
||||
return "%.1f%s" %(bytes, units[counter])
|
||||
|
||||
def blocks2bytes(blocks, blocksize):
|
||||
bytes = float(blocks) * float(blocksize) / 1024
|
||||
bytes = float(blocks) * float(blocksize)
|
||||
return bytes
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
diskmoninstance = disk.diskmon()
|
||||
notmounted = "Not mounted partitions:"
|
||||
for partition in diskmoninstance.partitions:
|
||||
print "Device:\t\t" + str(partition["device"])
|
||||
print "UUID:\t\t" + str(partition["uuid"])
|
||||
if partition.has_key("mountpoint"):
|
||||
totalbytes = blocks2bytes(partition["total blocks"], partition["blocksize"])
|
||||
totalhuman = bytes2human(totalbytes)
|
||||
#totalhuman = bytes2human(totalbytes)
|
||||
freebytes = blocks2bytes(partition["free blocks"], partition["blocksize"])
|
||||
freehuman = bytes2human(freebytes)
|
||||
print "Mountpoint:\t" + str(partition["mountpoint"]) + \
|
||||
"\nFilesystem:\t" + str(partition["filesystem"]) + \
|
||||
"\nUsage:\t\t%.2f%s/%.2f%s\n" %(freehuman[0], freehuman[1], totalhuman[0], totalhuman[1])
|
||||
#freehuman = bytes2human(freebytes)
|
||||
print "Device:\t\t%s" %(partition["device"]) + \
|
||||
"\nUUID:\t\t%s" %(partition["uuid"]) + \
|
||||
"\nMountpoint:\t%s" %(partition["mountpoint"]) + \
|
||||
"\nFilesystem:\t%s" %(partition["filesystem"]) + \
|
||||
"\nUsage:\t\t%s/%s" %(bytes2human(freebytes), bytes2human(totalbytes)) + \
|
||||
"\nFiles:\t\t%s\n" %(partition["files"])
|
||||
else:
|
||||
print "\n"
|
||||
notmounted = notmounted + " " + partition["device"]
|
||||
|
||||
print notmounted
|
||||
|
||||
print "debug output"
|
||||
print diskmoninstance.partitions
|
||||
|
||||
#end of file
|
||||
|
|
Reference in New Issue