From 17e6cea6262c567880746609f4a80bb0b6089f53 Mon Sep 17 00:00:00 2001 From: greenbreakfast Date: Mon, 9 Nov 2015 19:46:40 -0500 Subject: [PATCH] implemented disk usage --- bin/change-password.sh | 3 +- bin/disk-space.sh | 53 +++++++++++++++++++++++++ tools/upload_misc.sh | 1 + www/apps/onion-status/onion-status.html | 40 +++++++++++++++++-- 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100755 bin/disk-space.sh diff --git a/bin/change-password.sh b/bin/change-password.sh index 97a3d95..f6ffbc6 100755 --- a/bin/change-password.sh +++ b/bin/change-password.sh @@ -1,7 +1,6 @@ #!/bin/sh -### calling this will shutdown the Omega -### only if called with -f option +### change the password of the specified user bUsage=1 diff --git a/bin/disk-space.sh b/bin/disk-space.sh new file mode 100755 index 0000000..0dd8ef2 --- /dev/null +++ b/bin/disk-space.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +### find the disk space used, available, and total + + +# function to check a specific filesystem +# arg1 - the mount point +CheckMountPoint () { + local df=$(df $1 | grep -v Filesystem) + local dfReduced=$(echo "$df" | sed -e 's/^[[:graph:]]*[[:space:]]*[[:graph:]]*[[:space:]]*//' -e 's/[[:graph:]]*%.*$//') + + echo "$dfReduced" +} + +# function to find used space +# arg1 - the mount point data from CheckMountPoint +FindUsedSpace () { + local dfUsed=$(echo "$1" | sed -e 's/[[:space:]].*$//') + + echo "$dfUsed" +} + +# function to find free space +# arg1 - the mount point data from CheckMountPoint +FindFreeSpace () { + local dfFree=$(echo "$1" | sed -e 's/^[[:graph:]]*[[:space:]]*//') + + echo "$dfFree" +} + + +######################## +##### Main Program ##### + +# find free and used space on / mount point +mount0="/" +disk0=$(CheckMountPoint "$mount0") +disk0Free=$(FindFreeSpace "$disk0") +disk0Used=$(FindUsedSpace "$disk0") + +# find free and used space on /rom mount point +mount1="/rom" +disk1=$(CheckMountPoint "$mount1") +disk1Free=$(FindFreeSpace "$disk1") +disk1Used=$(FindUsedSpace "$disk1") + +# find the total numbers +free=$(($disk0Free + $disk1Free)) +used=$(($disk0Used + $disk1Used)) + +total=$(($free + $used)) + +echo "free:$free, used:$used, total:$total" diff --git a/tools/upload_misc.sh b/tools/upload_misc.sh index 026c61c..a5c3a1a 100755 --- a/tools/upload_misc.sh +++ b/tools/upload_misc.sh @@ -21,4 +21,5 @@ rsync --progress -rv ./rpcd/onion-console.sh root@$ipAddr:/usr/libexec/rpcd/onio rsync --progress -rv ./bin/factory-reset.sh root@$ipAddr:/usr/sbin/factory-reset rsync --progress -rv ./bin/power-down.sh root@$ipAddr:/usr/sbin/power-down rsync --progress -rv ./bin/change-password.sh root@$ipAddr:/usr/sbin/change-password +rsync --progress -rv ./bin/disk-space.sh root@$ipAddr:/usr/sbin/disk-space diff --git a/www/apps/onion-status/onion-status.html b/www/apps/onion-status/onion-status.html index e74cd4e..9e510ec 100644 --- a/www/apps/onion-status/onion-status.html +++ b/www/apps/onion-status/onion-status.html @@ -149,8 +149,8 @@

Storage

 
-

NEED PROGRESS HERE
LAZAR TO DO

- 50% +

{{diskUsed}} MB / {{diskTotal}} MB
Filesystem

+ {{diskPercentage}}
@@ -223,7 +223,7 @@
Bytes Transmitted
return Array(+(zero > 0 && zero)).join("0") + num; } - // convert milliseconds to + // convert milliseconds to a human readable string function millisecondsToStr (milliseconds) { var ret = ''; @@ -296,6 +296,9 @@
Bytes Transmitted
//Get received and transmitted bytes updateRxTx(); refreshRxTx(10000); + + //Get the disk usage + updateDiskUsage(); }); } }; @@ -332,6 +335,36 @@
Bytes Transmitted
stopRefreshRxTx(); } }; + + var updateDiskUsage = function () { + if (self.sessionProvider.isAlive() === true ) { + onionConsole.getService('onion-ubus-provider', function (ubus) { + var params = { + command: '/usr/sbin/disk-space', + params: [] + }; + + // make the ubus call + ubus.request('file', 'exec', params, function (data) { + if (data && data[0] === 0) { + var diskData = String(data[1].stdout); + var diskFree = diskData.replace(/.*free:(\d+).*/, '$1'); + self.diskUsed = diskData.replace(/.*used:(\d+).*/, '$1'); + self.diskTotal = diskData.replace(/.*total:(\d+).*/, '$1'); + + // find percentage of disk used + self.diskPercentage = ((self.diskUsed / self.diskTotal) * 100).toFixed(2) + + // convert units to MB + self.diskUsed = (self.diskUsed / 1000).toFixed(3); + self.diskTotal = (self.diskTotal / 1000).toFixed(3); + } + }); + }); + } else { + alert('Session time out! Failed to get disk space data!'); + } + }; /* var refreshStatus = function (interval) { @@ -363,6 +396,7 @@
Bytes Transmitted
refreshRxTx: refreshRxTx, stopRefreshRxTx: stopRefreshRxTx, updateRxTx: updateRxTx, + updateDiskUsage: updateDiskUsage, //refreshStatus: refreshStatus, //updateStatus: updateStatus, });