DiskSmallGraph.php 3.2 KB

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