MemorySmallGraph.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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->configChartsSettings->timeframe = 'day';
  50. $this->timeframe = 'day';
  51. }
  52. public function prepareAjaxData()
  53. {
  54. session_write_close();
  55. $labels = [];
  56. $dataSets = [
  57. 'maxmem' => [],
  58. ];
  59. foreach ($this->rrdDataQuery() as $rrd)
  60. {
  61. $labels[] = $rrd->date;
  62. $dataSets['mem'][] = isset($rrd->mem) ? $rrd->mem : 0;
  63. $dataSets['maxmem'][] = isset($rrd->maxmem) ? $rrd->maxmem : 0;
  64. }
  65. //Labels
  66. $this->setLabels($labels);
  67. //Memory
  68. $lang = sl('lang');
  69. $dataSet = new DataSet();
  70. $dataSet->setTitle($lang->tr('Memory Usage'))
  71. ->setData($dataSets['mem'])
  72. ->setConfigurationDataSet([
  73. "backgroundColor" => 'rgba(39, 133, 134, 0.91)',
  74. "borderColor" => 'rgba(39, 133, 134, 1)',
  75. ]);
  76. $this->addDataSet($dataSet);
  77. //Total
  78. $dataSet = new DataSet();
  79. $dataSet->setTitle($lang->tr('Total'))
  80. ->setData($dataSets['maxmem'])
  81. ->setConfigurationDataSet([
  82. "backgroundColor" => 'rgba(174, 198, 57, 0.79)',
  83. "borderColor" => 'rgba(174, 198, 57, 1)',
  84. ]);
  85. $this->addDataSet($dataSet);
  86. }
  87. }