Created
January 6, 2012 06:01
-
-
Save yyuu/1569253 to your computer and use it in GitHub Desktop.
df in python on Linux
This file contains hidden or 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
#!/usr/bin/env python | |
from __future__ import with_statement | |
import contextlib | |
import os | |
import sys | |
print "Filesystem\tMounted on\tUse%\tIUse%" | |
with contextlib.closing(open('/etc/mtab')) as fp: | |
for m in fp: | |
fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = m.split() | |
if fs_spec.startswith('/'): | |
r = os.statvfs(fs_file) | |
block_usage_pct = 100.0 - (float(r.f_bavail) / float(r.f_blocks) * 100) | |
inode_usage_pct = 100.0 - (float(r.f_favail) / float(r.f_files) * 100) | |
print "%s\t%s\t\t%d%%\t%d%%" % (fs_spec, fs_file, block_usage_pct, inode_usage_pct) | |
# vim:set ft=python : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I really love the code. I'm using it in a simple web interface to monitor a raspberry pi.
I made a few improvements to make it usable as a python module.
Cheers,
Tatic0