PHP_SMART_HOME_V3/app/api/ServerApi.php

44 lines
1.3 KiB
PHP
Raw Normal View History

2020-07-27 17:52:43 +00:00
<?php
class ServerApi extends ApiController {
private function getSystemMemInfo()
{
$data = explode("\n", file_get_contents("/proc/meminfo"));
$meminfo = array();
foreach ($data as $line) {
$data = explode(":", $line);
if (count($data)!=2) continue;
$meminfo[$data[0]] = trim($data[1]);
}
return $meminfo;
}
2020-10-31 20:37:29 +00:00
private function getProcessorUsage(){
$loads=sys_getloadavg();
$core_nums=trim(shell_exec("grep -P '^physical id' /proc/cpuinfo|wc -l"));
$load = round($loads[0]/($core_nums + 1)*100, 2);
return $load;
}
2020-07-27 17:52:43 +00:00
public function default(){
//$this->requireAuth();
$response = [
2020-10-31 20:37:29 +00:00
"cpu_load" => $this->getProcessorUsage(),
2020-07-27 17:52:43 +00:00
"uptime" => shell_exec('uptime -p'),
"ramFree" => $this->getSystemMemInfo()["MemFree"],
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
"diskFree" => disk_free_space("/"),
"diskTotal" => disk_total_space("/"),
2020-10-31 20:37:29 +00:00
"serverTime" => date('m. d. Y H:i:s'),
"serverTimeZone" => date('e'),
2020-07-27 17:52:43 +00:00
];
$this->response($response);
}
2020-07-30 14:31:25 +00:00
public function logStatus()
{
$logKeeper = new LogMaintainer();
$response = $logKeeper::getStats();
$this->response($response);
}
2020-07-27 17:52:43 +00:00
}