ServiceCpuGraph.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\ServiceGraph\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Models\RrdData;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Line;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Models\DataSet;
  26. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  27. /**
  28. * Class ServiceCpuGraph
  29. * @package ModulesGarden\Servers\ProxmoxCloudVps\App\UI\ServiceGraph\Pages
  30. */
  31. class ServiceCpuGraph extends BaseGraph
  32. {
  33. protected $id = 'serviceCpuGraph';
  34. protected $name = 'serviceCpuGraph';
  35. /**
  36. *
  37. */
  38. public function initContent()
  39. {
  40. $this->unsetShowTitle();
  41. //yAxes
  42. $this->updateChartScale('yAxes', [
  43. [
  44. 'scaleLabel' => [
  45. 'display' => true,
  46. 'labelString' => sl('lang')->tr("CPU %")
  47. ],
  48. 'ticks' => [
  49. 'beginAtZero' => true,
  50. 'fontSize' => 10
  51. ],
  52. ]]);
  53. //xAxes
  54. $this->updateChartScale('xAxes', [
  55. [
  56. 'display' => false,
  57. ]]);
  58. //Tooltip
  59. $this->updateChartOption('tooltips', [
  60. 'callbacks' => [
  61. 'label' => 'mgTooltipCpu'
  62. ]
  63. ]);
  64. }
  65. /**
  66. * @throws \Exception+
  67. */
  68. public function prepareAjaxData()
  69. {
  70. session_write_close();
  71. $labels = [];
  72. $dataSets = [
  73. 'cpu' => []
  74. ];
  75. foreach ($this->rrdDataQuery() as $rrd)
  76. {
  77. $labels[] = $rrd->date;
  78. $dataSets['cpu'][] = (isset($rrd->cpu) ? (float)$rrd->cpu : 0) * 100;
  79. }
  80. //Labels
  81. $this->setLabels($labels);
  82. //CPU Usage
  83. $lang = sl('lang');
  84. $dataSet = new DataSet();
  85. $dataSet->setTitle($lang->tr('CPU Usage'))
  86. ->setData($dataSets['cpu'])
  87. ->setConfigurationDataSet([
  88. "backgroundColor" => "rgba(174, 198, 57, 0.79)",
  89. "borderColor" => "rgba(174, 198, 57, 1)"
  90. ]);
  91. $this->addDataSet($dataSet);
  92. }
  93. }