| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (Oct 1, 2018)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Graph\Pages;
- use ModulesGarden\ProxmoxAddon\Core\Helper\DatabaseCache;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Select;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Line;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Models\DataSet;
- use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\di;
- use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
- class DiskGraph extends Line implements ClientArea, AdminArea
- {
- use GraphData;
- protected $id = 'diskGraph';
- protected $graphSettingsEnabled = true;
- protected $graphSettingsKey = 'diskGraphSettings';
- protected $displayScaleLabel = true;
- protected $graphHeight = null;
- protected $graphWidth = null;
- public function initContent()
- {
- $this->initIds('diskGraph');
- $this->setRawTitle( di('lang')->translate('diskGraph'));
- $selectScope = new Select('timeframe');
- $selectScope->setAvailableValues($this->chartOptions());
- $selectScope->setDefaultValue('week');
- $this->addSettingField($selectScope);
- $this->updateChartScale('yAxes', [
- [
- 'scaleLabel' => [
- 'display' => $this->displayScaleLabel,
- 'labelString' => sl('lang')->tr('Bytes/s'),
- ],
- 'ticks' => [
- 'callback' => 'mgBytesToSize',
- 'beginAtZero' => true,
- 'fontSize' => 10
- ],
- ]]);
- $this->updateChartOption('tooltips', [
- 'callbacks' => [
- 'label' => 'mgTooltipCallbackForDisk'
- ]
- ]);
- }
- public function prepareAjaxData()
- {
- session_write_close();
- if ($this->configChartsSettings->timeframe)
- {
- $this->timeframe = $this->configChartsSettings->timeframe;
- }
- $rrdata = DatabaseCache::loadData(
- $this->graphSettingsKey .$this->timeframe .$this->getWhmcsParamByKey('serviceid'). '_cacheData', [$this, 'chartData'], 30, true);
- $labels = [];
- $dataSets = [
- 'diskread' => [],
- 'diskwrite' => [],
- ];
- $dateFormat = in_array($this->timeframe, ['hour', 'day']) ? "H:i:s" : "Y-m-d";
- foreach ($this->convertData($rrdata) as $rrd)
- {
- $labels[] = date($dateFormat, $rrd['time']);
- $dataSets['diskread'][] = (isset($rrd['diskread']) ? $rrd['diskread'] : 0);
- $dataSets['diskwrite'][] = (isset($rrd['diskwrite']) ? $rrd['diskwrite'] : 0);
- }
- //Labels
- $this->setLabels($labels);
- //Memory
- $lang = sl('lang');
- $dataSet = new DataSet();
- $dataSet->setTitle($lang->tr('Disk Read'))
- ->setData($dataSets['diskread'])
- ->setConfigurationDataSet([
- "backgroundColor" => 'rgba(174, 198, 57, 0.79)',
- "borderColor" => 'rgba(174, 198, 57, 1)',
- ]);
- $this->addDataSet($dataSet);
- //Total
- $dataSet = new DataSet();
- $dataSet->setTitle($lang->tr('Disk Write'))
- ->setData($dataSets['diskwrite'])
- ->setConfigurationDataSet([
- "backgroundColor" => 'rgba(39, 133, 134, 0.91)',
- "borderColor" => 'rgba(39, 133, 134, 1)',
- ]);
- $this->addDataSet($dataSet);
- }
- }
|