MemorySmallGraph.php 3.1 KB

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