RrdData.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Models;
  3. use ModulesGarden\ProxmoxAddon\Core\Models\ExtendedEloquentModel;
  4. /**
  5. * Class RrdData
  6. * @package ModulesGarden\ProxmoxAddon\App\Models
  7. * @method static $this ofHostingId($hostingId)
  8. * @method sinceDayAgo()
  9. */
  10. class RrdData extends ExtendedEloquentModel
  11. {
  12. /** @var string */
  13. protected $table = 'RrdData';
  14. protected $fillable = [ 'hosting_id', 'vm_id', 'diskread', 'diskwrite','cpu','maxcpu','mem','maxmem','netin','netout','time'
  15. ];
  16. public $timestamps = false;
  17. public function scopeOfHostingId($query, $hostingId)
  18. {
  19. return $query->where("hosting_id", $hostingId);
  20. }
  21. public function scopeSinceDayAgo($query)
  22. {
  23. $now = new \DateTime();
  24. $now->modify('-24 hours');
  25. return $query->where("time", ">=",$now->format("Y-m-d H:i:s"));
  26. }
  27. public function scopeSinceHourAgo($query)
  28. {
  29. $now = new \DateTime();
  30. $now->modify('-1 hours');
  31. return $query->where("time", ">=",$now->format("Y-m-d H:i:s"));
  32. }
  33. public function scopeOlderThanDayAgo($query)
  34. {
  35. $now = new \DateTime();
  36. $now->modify('-24 hours');
  37. return $query->where("time", "<=",$now->format("Y-m-d H:i:s"));
  38. }
  39. }