Created
February 17, 2017 20:27
-
-
Save mmedvede/ca6373f5034e5e6aa4863af0661c5995 to your computer and use it in GitHub Desktop.
dstat plugin for showing free disk space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Drop this into /usr/local/share/dstat (or equivalent). | |
# Use it like so: | |
# DSTAT_FSSPACE_MOUNTS=/,/opt dstat --fsspace" | |
class dstat_plugin(dstat): | |
""" Disk use, based on freespace plugin """ | |
def __init__(self): | |
self.nick = ('used', 'free', 'total') | |
self.cols = len(self.nick) | |
def vars(self): | |
mounts = os.getenv('DSTAT_FSSPACE_MOUNTS') or '/' | |
mounts = mounts.split(',') or [] | |
return mounts | |
def name(self): | |
return ['fs' + name for name in self.vars] | |
def extract(self): | |
self.val['total'] = (0, 0) | |
for name in self.vars: | |
try: | |
res = os.statvfs(name) | |
stats = [ | |
res.f_blocks - res.f_bavail, # used | |
res.f_bavail, # free | |
res.f_blocks, # total | |
] | |
frsize = float(res.f_frsize) | |
self.val[name] = list(map(lambda x: x * frsize, stats)) | |
except Exception as e: | |
self.val[name] = [-1] * len(self.nick) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment