Summary.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Aug 14, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\ProxmoxAddon\App\UI\NodeDetail\Pages;
  20. use MGProvision\Proxmox\v2\models\Node;
  21. use ModulesGarden\ProxmoxAddon\App\Libs\Format;
  22. use ModulesGarden\ProxmoxAddon\App\Services\BaseService;
  23. use ModulesGarden\ProxmoxAddon\Core\UI\Builder\BaseContainer;
  24. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  25. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AjaxElementInterface;
  26. use ModulesGarden\ProxmoxAddon\Core\UI\ResponseTemplates\RawDataJsonResponse;
  27. class Summary extends BaseContainer implements AdminArea, AjaxElementInterface
  28. {
  29. use BaseService;
  30. protected $id = 'mg-summary';
  31. protected $name = 'mg-summary-name';
  32. protected $title = 'mg-summary-title';
  33. protected $vueComponent = true;
  34. protected $defaultVueComponentName = 'mg-details';
  35. public function initContent()
  36. {
  37. }
  38. public function returnAjaxData()
  39. {
  40. $data = [];
  41. $this->setServerId($this->getRequestValue('serverId'))
  42. ->getApi()
  43. ->setInstance();
  44. $node = new Node($this->getRequestValue('id'));
  45. //Summary
  46. $status = $node->getStatus();
  47. $status['memory']['percent'] = round($status['memory']['used'] / $status['memory']['total'] * 100);
  48. $status['swap']['percent'] = round($status['swap']['used'] / $status['swap']['total'] * 100);
  49. $status['rootfs']['percent'] = round($status['rootfs']['used'] / $status['rootfs']['total'] * 100);
  50. $status['rootfs']['free'] = $status['rootfs']['total'] - $status['rootfs']['used'];
  51. foreach ($status['memory'] as $k => &$v)
  52. {
  53. if ($k == 'percent')
  54. {
  55. break;
  56. }
  57. $v = Format::convertBytes($v);
  58. }
  59. foreach ($status['rootfs'] as $k => &$v)
  60. {
  61. if ($k == 'percent')
  62. {
  63. break;
  64. }
  65. $v = Format::convertBytes($v);
  66. }
  67. foreach ($status['swap'] as $k => &$v)
  68. {
  69. if ($k == 'percent')
  70. {
  71. break;
  72. }
  73. $v = Format::convertBytes($v);
  74. }
  75. $status['uptime'] = Format::uptime($status['uptime']);
  76. $status['cpu'] = $status['cpu'] ? round($status['cpu'] * 100, 2) . " %" : "0 %";
  77. $data['status'] = $status;
  78. $data['node'] = $node->getNode();
  79. return (new RawDataJsonResponse(['data' => $data]));
  80. }
  81. }