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