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.py

46 lines
1.5 KiB
Python
Raw Normal View History

""" disk monitor """
class diskmon(object):
"""collect information about local partitions"""
def __init__(self):
self.update()
def update(self):
"""run collection of data"""
2012-05-20 14:21:15 +02:00
import os
self.partitions = []
uuids = os.listdir("/dev/disk/by-uuid")
for uuid in uuids:
2012-05-20 15:27:27 +02:00
part = {}
part["device"] = str("/dev/" + os.readlink("/dev/disk/by-uuid/" + uuid)[6:])
part["uuid"] = uuid
#getting mountpoint for partition from mtab
2012-05-20 13:37:17 +02:00
mtab = open("/etc/mtab", "r")
#for line in
for line in mtab:
2012-05-20 15:27:27 +02:00
if part["device"] in line:
part["mountpoint"] = line.split()[1]
part["filesystem"] = line.split()[2]
2012-05-20 12:40:07 +02:00
#getting block infos
2012-05-20 15:27:27 +02:00
if os.path.ismount(part["mountpoint"]):
fs = os.statvfs(part["mountpoint"])
2012-05-21 00:45:17 +02:00
part["mounted"] = "1" #mounted flag
2012-05-20 15:27:27 +02:00
part["blocksize"] = fs.f_bsize #blocksize
part["total blocks"] = fs.f_blocks #total blocks
part["free blocks"] = fs.f_bavail #free blocks
2012-05-21 00:45:17 +02:00
part["used blocks"] = part["total blocks"] - part["free blocks"]
part["files"] = fs.f_files #total files
2012-05-20 13:37:17 +02:00
break
2012-05-20 12:40:07 +02:00
2012-05-20 13:37:17 +02:00
mtab.close()
#adding partition to list
2012-05-20 13:37:17 +02:00
self.partitions.append(part)
#end of file