Skip to content

Commit

Permalink
implemented disk usage
Browse files Browse the repository at this point in the history
  • Loading branch information
greenbreakfast committed Nov 10, 2015
1 parent 5ec6164 commit 17e6cea
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 5 deletions.
3 changes: 1 addition & 2 deletions bin/change-password.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
53 changes: 53 additions & 0 deletions bin/disk-space.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions tools/upload_misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

40 changes: 37 additions & 3 deletions www/apps/onion-status/onion-status.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ <h4 class="card-title" id="online">Storage</h4>
<h6 class="card-subtitle text-muted">&nbsp;</h6>
</div>
<div class="card-block">
<p><span>NEED PROGRESS HERE</span><br><strong>LAZAR TO DO</strong></p>
<progress class="progress progress-warning" value="50" max="100">50%</progress>
<p><span>{{diskUsed}}</span> MB / <span>{{diskTotal}}</span> MB<br><strong>Filesystem</strong></p>
<progress class="progress progress-warning" value={{diskPercentage}} max="100">{{diskPercentage}}</progress>
</div>
</div>

Expand Down Expand Up @@ -223,7 +223,7 @@ <h6 class="card-subtitle text-muted">Bytes Transmitted</h6>
return Array(+(zero > 0 && zero)).join("0") + num;
}

// convert milliseconds to
// convert milliseconds to a human readable string
function millisecondsToStr (milliseconds) {
var ret = '';

Expand Down Expand Up @@ -296,6 +296,9 @@ <h6 class="card-subtitle text-muted">Bytes Transmitted</h6>
//Get received and transmitted bytes
updateRxTx();
refreshRxTx(10000);

//Get the disk usage
updateDiskUsage();
});
}
};
Expand Down Expand Up @@ -332,6 +335,36 @@ <h6 class="card-subtitle text-muted">Bytes Transmitted</h6>
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) {
Expand Down Expand Up @@ -363,6 +396,7 @@ <h6 class="card-subtitle text-muted">Bytes Transmitted</h6>
refreshRxTx: refreshRxTx,
stopRefreshRxTx: stopRefreshRxTx,
updateRxTx: updateRxTx,
updateDiskUsage: updateDiskUsage,
//refreshStatus: refreshStatus,
//updateStatus: updateStatus,
});
Expand Down

0 comments on commit 17e6cea

Please sign in to comment.