From 0d4b6b89c97c33c6150058df3c915e6b71d197ac Mon Sep 17 00:00:00 2001 From: jim-p Date: Thu, 22 May 2014 12:47:23 -0400 Subject: Display space usage for all mounted filesystems, not just /. Also display FS type and indicate if it's a RAM disk. --- usr/local/www/includes/functions.inc.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'usr/local/www/includes/functions.inc.php') diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php index 7ad0ed9..78043e8 100644 --- a/usr/local/www/includes/functions.inc.php +++ b/usr/local/www/includes/functions.inc.php @@ -191,9 +191,29 @@ function get_temp() { return $temp_out; } -function disk_usage() { +/* Get mounted filesystems and usage. Do not display entries for virtual filesystems (e.g. devfs, nullfs, unionfs) */ +function get_mounted_filesystems() { + $mout = ""; + $filesystems = array(); + exec("/bin/df -Tht ufs,zfs,cd9660 | /usr/bin/awk '{print $1, $2, $3, $6, $7;}'", $mout); + + /* Get rid of the header */ + array_shift($mout); + foreach ($mout as $fs) { + $f = array(); + list($f['device'], $f['type'], $f['total_size'], $f['percent_used'], $f['mountpoint']) = explode(' ', $fs); + + /* We dont' want the trailing % sign. */ + $f['percent_used'] = trim($f['percent_used'], '%'); + + $filesystems[] = $f; + } + return $filesystems; +} + +function disk_usage($slice = '/') { $dfout = ""; - exec("/bin/df -h | /usr/bin/grep -w '/' | /usr/bin/awk '{ print $5 }' | /usr/bin/cut -d '%' -f 1", $dfout); + exec("/bin/df -h {$slice} | /usr/bin/tail -n 1 | /usr/bin/awk '{ print $5 }' | /usr/bin/cut -d '%' -f 1", $dfout); $diskusage = trim($dfout[0]); return $diskusage; -- cgit v1.1