BaseGraph.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\ServiceGraph\Pages;
  3. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  4. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  5. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  6. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Graphs\Line;
  7. use Illuminate\Database\Capsule\Manager as DB;
  8. class BaseGraph extends Line implements ClientArea, AdminArea
  9. {
  10. use ProductService;
  11. protected $graphSettingsEnabled = false;
  12. protected $graphHeight = 70;
  13. protected $graphWidth = 200;
  14. protected $showTitle = false;
  15. protected $title = '';
  16. protected $legend = [
  17. 'display' => false,
  18. 'position' => 'top'
  19. ];
  20. protected function rrdDataQuery(){
  21. $hi = (int) $this->getWhmcsParamByKey('serviceid');
  22. $now = new \DateTime();
  23. $now->modify('-1 hours');
  24. $since = $now->format("Y-m-d H:i:s");
  25. //Query
  26. 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`
  27. WHERE hosting_id = {$hi} AND `time` >= '{$since}'
  28. ) as x GROUP BY date ORDER BY `date` ASC");
  29. }
  30. }