Server Stats API
This commit is contained in:
parent
5ee1af2571
commit
49d24f8e0e
28
app/api/ServerApi.php
Normal file
28
app/api/ServerApi.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
public function default(){
|
||||
//$this->requireAuth();
|
||||
$response = [
|
||||
"cpu_load" => sys_getloadavg()[0],
|
||||
"uptime" => shell_exec('uptime -p'),
|
||||
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
||||
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
||||
"diskFree" => disk_free_space("/"),
|
||||
"diskTotal" => disk_total_space("/"),
|
||||
"serverTime" => date('m. d. Y H:i:s - e'),
|
||||
];
|
||||
$this->response($response);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user