Added uptime information to API.

pull/113/head
Joe Prochazka 2016-03-05 03:37:32 -05:00
rodzic 9a811f305e
commit 1aba8d1cb1
5 zmienionych plików z 31 dodań i 7 usunięć

Wyświetl plik

@ -30,6 +30,9 @@ threads I was able to add these very informative graphs.
## Third Party Software
Thanks to the people over at JetBrains for the complementary licenses for PhpStorm which is being used
to develop the portal portion of this project. https://www.jetbrains.com
I would like to thank the developers and contributors to the following projects. Without their
hard work and dedication this project would not have been possible.

Wyświetl plik

@ -220,7 +220,7 @@ EOF;
// Add the administrator account.
require_once('../classes/account.class.php');
$account->addAdministrator($name, $email, $login, $password1);
$account->addAdministrator($_POST['name'], $_POST['email'], $_POST['login'], $_POST['password1']);
// Mark the installation as complete.
$installed = TRUE;

Wyświetl plik

@ -28,7 +28,7 @@
// SOFTWARE. //
/////////////////////////////////////////////////////////////////////////////////////
$possibleActions = array("getOsInformation", "getCpuInformation", "getMemoryInformation", "getHddInformation", "getNetworkInformation");
$possibleActions = array("getOsInformation", "getCpuInformation", "getMemoryInformation", "getHddInformation", "getNetworkInformation", "getUptimeInformation");
if (isset($_GET['action']) && in_array($_GET["action"], $possibleActions)) {
switch ($_GET["action"]) {
@ -47,6 +47,9 @@
case "getNetworkInformation":
$informationArray = getNetworkInformation();
break;
case "getNetworkInformation":
$informationArray = getUptimeInformation();
break;
}
exit(json_encode($informationArray));
} else {
@ -106,14 +109,29 @@
function getHddInformation() {
$hddInformation['free'] = round(disk_free_space("/") / 1024 / 1024 / 1024, 2);
$hddInformation['total'] = round(disk_total_space("/") / 1024 / 1024/ 1024, 2);
$hddInformation['used'] = $hddInformation['total'] - $stat['hdd_free'];
$hddInformation['used'] = $hddInformation['total'] - $hddInformation['free'];
$hddInformation['percent'] = round(sprintf('%.2f',($hddInformation['used'] / $hddInformation['total']) * 100), 2);
return $hddInformation;
}
function getNetworkInformation() {
$networkInformation['rx'] = round(trim(file_get_contents("/sys/class/net/eth0/statistics/rx_bytes")) / 1024 / 1024 / 1024, 2);
$networkInformation['tx'] = round(trim(file_get_contents("/sys/class/net/eth0/statistics/tx_bytes")) / 1024 / 1024 / 1024, 2);
$networkInformation['rx'] = round(trim(file_get_contents("/sys/class/net/eth0/statistics/rx_bytes")) / 125000, 2);
$networkInformation['tx'] = round(trim(file_get_contents("/sys/class/net/eth0/statistics/tx_bytes")) / 125000, 2);
return $networkInformation;
}
function getUptimeInformation() {
$procUptime = file('/proc/uptime');
$uptimeArray = preg_split('/ /', $procUptime);
$uptime['inSeconds'] = trim($uptimeArray[0]);
$uptime['hours'] = floor($uptime['inSeconds'] / 3600);
$uptime['minutes'] = floor(($uptime['inSeconds'] - ($uptime['hours'] * 3600)) / 60);
$uptime['seconds'] = floor($uptime['inSeconds'] % 60);
return $uptime;
//$idle['inSeconds'] = trim($uptimeArray[1]);
//$idle['hours'] = floor($idle['inSeconds'] / 3600);
//$idle['minutes'] = floor(($idle['inSeconds'] - ($idle['hours'] * 3600)) / 60);
//$idle['seconds'] = floor($idle['inSeconds'] % 60);
}
?>

Wyświetl plik

@ -9,8 +9,8 @@ $(document).ready(function () {
['Label', 'Value'],
['Memory', 100],
['CPU', 100],
['Network In', 100]
['Network Out', 100]
['Network In (Mbps)', 100]
['Network Out (Mbps)', 100]
]);
var options = {

Wyświetl plik

@ -33,6 +33,9 @@
<h2>System Charts</h2>
<div id="chart_div" style="width: 400px; height: 120px;"></div>
<h2>System Information</h2>
<ul>
<li>Uptime: </li>
</ul>
</div>
{/area}
{area:scripts}