socialnerds/hive
socialnerds
/
hive
Archived
1
0
Fork 0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
hive/monitor/disk_display.py

38 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python2 -B
""" simple display to show results of disk.py """
import disk
def bytes2human(bytes):
units = ["B", "KB", "MB", "GB", "TB", "PB", "EB"]
counter = 0
while bytes > 1024:
bytes = bytes / 1024
counter += 1
human = [bytes, units[counter]]
return human
def blocks2bytes(blocks, blocksize):
bytes = float(blocks) * float(blocksize)
return bytes
if __name__ == "__main__":
diskmoninstance = disk.diskmon()
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)
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])
else:
print "\n"
#end of file