mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
class System {
|
||
|
public function hostname() {
|
||
|
return shell_exec("hostname -f");
|
||
|
}
|
||
|
|
||
|
public function uptime() {
|
||
|
$uparray = explode(" ", exec("cat /proc/uptime"));
|
||
|
$seconds = round($uparray[0], 0);
|
||
|
$minutes = $seconds / 60;
|
||
|
$hours = $minutes / 60;
|
||
|
$days = floor($hours / 24);
|
||
|
$hours = floor($hours - ($days * 24));
|
||
|
$minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
|
||
|
$uptime= '';
|
||
|
if ($days != 0) {
|
||
|
$uptime .= $days . ' day' . (($days > 1)? 's ':' ');
|
||
|
}
|
||
|
if ($hours != 0) {
|
||
|
$uptime .= $hours . ' hour' . (($hours > 1)? 's ':' ');
|
||
|
}
|
||
|
if ($minutes != 0) {
|
||
|
$uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' ');
|
||
|
}
|
||
|
|
||
|
return $uptime;
|
||
|
}
|
||
|
|
||
|
public function usedMemory() {
|
||
|
$used = shell_exec("free -m | awk '/Mem:/ { total=$2 ; used=$3 } END { print used/total*100}'");
|
||
|
return floor($used);
|
||
|
}
|
||
|
|
||
|
public function processorCount() {
|
||
|
$procs = shell_exec("nproc --all");
|
||
|
return intval($proc);
|
||
|
}
|
||
|
|
||
|
public function loadAvg1Min() {
|
||
|
$load = exec("awk '{print $1}' /proc/loadavg");
|
||
|
return floatval($load);
|
||
|
}
|
||
|
|
||
|
public function systemLoadPercentage() {
|
||
|
return floor(($this->loadAvg1Min() * 100) / $this->processorCount());
|
||
|
}
|
||
|
}
|