ServiceNetworkGraph.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. class ServiceNetworkGraph extends BaseGraph
  28. {
  29. use ProductService;
  30. protected $id = 'serviceNetworkGraph';
  31. protected $name = 'serviceNetworkGraph';
  32. public function initContent()
  33. {
  34. $this->updateChartScale('yAxes', [
  35. [
  36. 'scaleLabel' => [
  37. 'display' => true,
  38. 'labelString' => sl('lang')->tr('Network')
  39. ],
  40. 'ticks' => [
  41. 'callback' => 'mgBytesToSize',
  42. 'beginAtZero' => true,
  43. 'fontSize' => 10
  44. ],
  45. ]]);
  46. //xAxes
  47. $this->updateChartScale('xAxes', [
  48. [
  49. 'display' => false,
  50. ]]);
  51. $this->updateChartOption('tooltips', [
  52. 'callbacks' => [
  53. 'label' => 'mgTooltipCallbackForNet'
  54. ]
  55. ]);
  56. }
  57. public function prepareAjaxData()
  58. {
  59. session_write_close();
  60. $labels = [];
  61. $dataSets = [
  62. 'netin' => [],
  63. 'netout' => [],
  64. ];
  65. foreach ($this->rrdDataQuery() as $rrd)
  66. {
  67. $labels[] = $rrd->date;
  68. $dataSets['netin'][] = isset($rrd->netin) ? $rrd->netin : 0;
  69. $dataSets['netout'][] = isset($rrd->netout) ? $rrd->netout : 0;
  70. }
  71. //Labels
  72. $this->setLabels($labels);
  73. //Net in
  74. $lang = sl('lang');
  75. $dataSet = new DataSet();
  76. $dataSet->setTitle($lang->tr('Net In'))
  77. ->setData($dataSets['netin'])
  78. ->setConfigurationDataSet([
  79. "backgroundColor" => 'rgba(174, 198, 57, 0.79)',
  80. "borderColor" => 'rgba(174, 198, 57, 1)',
  81. ]);
  82. $this->addDataSet($dataSet);
  83. //Net out
  84. $dataSet = new DataSet();
  85. $dataSet->setTitle($lang->tr('Net Out'))
  86. ->setData($dataSets['netout'])
  87. ->setConfigurationDataSet([
  88. "backgroundColor" => 'rgba(39, 133, 134, 0.91)',
  89. "borderColor" => 'rgba(39, 133, 134, 1)',
  90. ]);
  91. $this->addDataSet($dataSet);
  92. }
  93. }