CpuSmallGraph.php 2.8 KB

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