BaseSmallGraph.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Graph\Pages;
  3. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  4. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  5. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Line;
  6. use Illuminate\Database\Capsule\Manager as DB;
  7. class BaseSmallGraph extends Line implements ClientArea, AdminArea
  8. {
  9. protected $tableRowCol = 'lu-col-md-3';
  10. protected $graphSettingsEnabled = false;
  11. protected $graphHeight = 70;
  12. protected $graphWidth = 200;
  13. protected $showTitle = false;
  14. protected $title = '';
  15. protected $legend = [
  16. 'display' => false,
  17. 'position' => 'top'
  18. ];
  19. protected $timeframe = "day";
  20. protected $displayScaleLabel = true;
  21. protected function rrdDataQuery(){
  22. $hi = (int) $this->getWhmcsParamByKey('serviceid');
  23. $now = new \DateTime();
  24. $now->modify('-1 hours');
  25. $since = $now->format("Y-m-d H:i:s");
  26. $vmId = (int) \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->id;
  27. //Query
  28. return DB::select("SELECT AVG(diskread) AS diskread, AVG(diskwrite) AS diskwrite, AVG(cpu) AS cpu, AVG(maxcpu) AS maxcpu , AVG(mem) AS mem, AVG(maxmem) AS maxmem, AVG(netin) AS netin, AVG(netout) AS netout, `date` FROM (SELECT id, hosting_id, vm_id, (diskread), (diskwrite), (cpu), (maxcpu), (mem), (maxmem), (netin), (netout), DATE_FORMAT(FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(time) / 300) * 300), '%Y-%m-%d %H:%i') as `date` FROM `ProxmoxAddon_RrdData`
  29. WHERE hosting_id = {$hi} AND vm_id ={$vmId} AND `time` >= '{$since}'
  30. ) as x GROUP BY date ORDER BY `date` ASC");
  31. }
  32. }