ServiceMemoryGraph.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Oct 1, 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\Servers\ProxmoxCloudVps\App\UI\ServiceGraph\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Models\RrdData;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Line;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Models\DataSet;
  26. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  27. class ServiceMemoryGraph extends BaseGraph
  28. {
  29. protected $id = 'serviceMemoryGraph';
  30. protected $name = 'serviceMemoryGraph';
  31. public function initContent()
  32. {
  33. $this->updateChartScale('yAxes', [
  34. [
  35. 'scaleLabel' => [
  36. 'display' => true,
  37. 'labelString' => sl('lang')->tr('Memory')
  38. ],
  39. 'ticks' => [
  40. 'callback' => 'mgBytesToSize',
  41. 'beginAtZero' => true,
  42. 'fontSize' => 10
  43. ],
  44. ]]);
  45. //xAxes
  46. $this->updateChartScale('xAxes', [
  47. [
  48. 'display' => false,
  49. ]]);
  50. $this->updateChartOption('tooltips', [
  51. 'callbacks' => [
  52. 'label' => 'mgTooltipCallbackForMemory'
  53. ]
  54. ]);
  55. }
  56. public function prepareAjaxData()
  57. {
  58. session_write_close();
  59. $labels = [];
  60. $dataSets = [
  61. 'maxmem' => [],
  62. ];
  63. foreach ($this->rrdDataQuery() as $rrd)
  64. {
  65. $labels[] = $rrd->date;
  66. $dataSets['mem'][] = isset($rrd->mem) ? $rrd->mem : 0;
  67. $dataSets['maxmem'][] = isset($rrd->maxmem) ? $rrd->maxmem : 0;
  68. }
  69. //Labels
  70. $this->setLabels($labels);
  71. //Memory
  72. $lang = sl('lang');
  73. $dataSet = new DataSet();
  74. $dataSet->setTitle($lang->tr('Memory Usage'))
  75. ->setData($dataSets['mem'])
  76. ->setConfigurationDataSet([
  77. "backgroundColor" => 'rgba(39, 133, 134, 0.91)',
  78. "borderColor" => 'rgba(39, 133, 134, 1)',
  79. ]);
  80. $this->addDataSet($dataSet);
  81. //Total
  82. $dataSet = new DataSet();
  83. $dataSet->setTitle($lang->tr('Total'))
  84. ->setData($dataSets['maxmem'])
  85. ->setConfigurationDataSet([
  86. "backgroundColor" => 'rgba(174, 198, 57, 0.79)',
  87. "borderColor" => 'rgba(174, 198, 57, 1)',
  88. ]);
  89. $this->addDataSet($dataSet);
  90. }
  91. }