Status.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. ApplicationSettings::RegisterDefaultSetting("status", "disks", "/");
  3. class Status extends Controller {
  4. public function Index() {
  5. $vars=array();
  6. $vars['disks']=array();
  7. $disks=explode(",", ApplicationSettings::GetSetting("status", "disks"));
  8. foreach ($disks as $disk) {
  9. $vars['disks'][]=new DiskInfo($disk);
  10. }
  11. return new View("Status/index.view", $vars);
  12. }
  13. public function GetSystemInfo() {
  14. $info=new stdClass();
  15. if (function_exists("sys_getloadavg"))
  16. $info->load=sys_getloadavg();
  17. else
  18. $info->load=array(rand(0, 4), rand(0, 4), rand(0, 4));
  19. $data=explode("\n", trim(file_get_contents("/proc/meminfo")));
  20. $memInfo=array();
  21. foreach ($data as $line) {
  22. list($key, $val)=explode(":", $line);
  23. $memInfo[$key]=explode(" ", trim($val))[0];
  24. }
  25. $info->memFree=$memInfo['MemFree'];
  26. $info->memTotal=$memInfo['MemTotal'];
  27. $info->memUsage=(($memInfo['MemTotal']-$memInfo['MemFree'])/$memInfo['MemTotal'])*100;
  28. $cpuTemp=(int)file_get_contents("/sys/class/thermal/thermal_zone0/temp");
  29. $info->cpuTemp=$cpuTemp/1000;
  30. return json_encode($info);
  31. }
  32. public function GetProcesses() {
  33. $lines=array();
  34. exec("ps aux", $lines);
  35. if (count($lines)==0) {
  36. $output=file_get_contents("/ps.txt");
  37. $output=htmlspecialchars($output);
  38. $lines=explode("\n", $output);
  39. }
  40. $header=preg_split('/\s+/', $lines[0]);
  41. for ($i=0; $i<count($lines); $i++)
  42. $lines[$i]=preg_split('/\s+/', $lines[$i], count($header));
  43. return json_encode($lines);
  44. }
  45. public function GetUptime() {
  46. $uptime=exec("uptime");
  47. if ($uptime=="")
  48. $uptime="17:16:18 up 22 days, 9:39, 1 user, load average: 2.10, 2.18, 2.33";
  49. $matches=array();
  50. preg_match("/(\d+) days,\s*(\d*):(\d*)/", $uptime, $matches);
  51. $obj=new stdClass();
  52. $obj->days=$matches[1];
  53. $obj->hours=$matches[2];
  54. $obj->minutes=$matches[3];
  55. return json_encode($obj);
  56. }
  57. }