where('status', 'active')->whereNotNull('vmid')->get(); foreach ($vms as $vm) { try { $raw = $this->proxmox->getVMStatus((int) $vm->vmid); $normalized = $this->proxmox->normalizeLiveStatus($raw); VmMetric::query()->create([ 'customer_id' => $vm->id, 'cpu' => $normalized['cpu'], 'mem' => $normalized['mem'], 'maxmem' => $normalized['maxmem'], 'disk' => $normalized['disk'], 'maxdisk' => $normalized['maxdisk'], 'recorded_at' => now(), ]); VmMetric::query() ->where('customer_id', $vm->id) ->where('recorded_at', '<', now()->subDays(7)) ->delete(); $count++; } catch (\Throwable) { // } } return $count; } }