Skip to content

Instantly share code, notes, and snippets.

@mmedvede
Created February 17, 2017 20:27
Show Gist options
  • Save mmedvede/ca6373f5034e5e6aa4863af0661c5995 to your computer and use it in GitHub Desktop.
Save mmedvede/ca6373f5034e5e6aa4863af0661c5995 to your computer and use it in GitHub Desktop.
dstat plugin for showing free disk space
# 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