graph_servers_day.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. if(!DEFINED('EGP'))
  3. exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
  4. class graph_servers_day extends cron
  5. {
  6. function __construct()
  7. {
  8. global $sql, $start_point;
  9. $servers = $sql->query('SELECT `id`, `date` FROM `servers` ORDER BY `id` ASC');
  10. while($server = $sql->get($servers))
  11. {
  12. if($server['date']+86400 > $start_point)
  13. continue;
  14. $aGraph = array('online' => 0, 'cpu' => 0, 'ram' => 0, 'hdd' => 0, 'time' => 0);
  15. $sql->query('SELECT `online`, `cpu`, `ram`, `hdd` FROM `graph_hour` WHERE `server`="'.$server['id'].'" AND `time`>"'.($start_point-86400).'" ORDER BY `id` DESC LIMIT 24');
  16. $n = $sql->num();
  17. if(!$n)
  18. continue;
  19. while($graph = $sql->get())
  20. {
  21. $aGraph['online'] += $graph['online'];
  22. $aGraph['cpu'] += $graph['cpu'];
  23. $aGraph['ram'] += $graph['ram'];
  24. $aGraph['hdd'] += $graph['hdd'];
  25. }
  26. $aGraph['online'] = $aGraph['online']/$n;
  27. $aGraph['cpu'] = $aGraph['cpu']/$n;
  28. $aGraph['ram'] = $aGraph['ram']/$n;
  29. $aGraph['hdd'] = $aGraph['hdd']/$n;
  30. $sql->query('INSERT INTO `graph_day` set `server`="'.$server['id'].'",'
  31. .'`online`="'.$aGraph['online'].'",'
  32. .'`cpu`="'.$aGraph['cpu'].'",'
  33. .'`ram`="'.$aGraph['ram'].'",'
  34. .'`hdd`="'.$aGraph['hdd'].'", `time`="'.$start_point.'"');
  35. }
  36. return NULL;
  37. }
  38. }
  39. ?>