 da195fd2fe
			
		
	
	
		da195fd2fe
		
			
		
	
	
	
	
		
			
			* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers\Api\Client\Servers;
 | |
| 
 | |
| use Carbon\Carbon;
 | |
| use App\Models\Server;
 | |
| use Illuminate\Cache\Repository;
 | |
| use App\Transformers\Api\Client\StatsTransformer;
 | |
| use App\Repositories\Daemon\DaemonServerRepository;
 | |
| use App\Http\Controllers\Api\Client\ClientApiController;
 | |
| use App\Http\Requests\Api\Client\Servers\GetServerRequest;
 | |
| use Dedoc\Scramble\Attributes\Group;
 | |
| use Illuminate\Http\Client\ConnectionException;
 | |
| 
 | |
| #[Group('Server', weight: 3)]
 | |
| class ResourceUtilizationController extends ClientApiController
 | |
| {
 | |
|     /**
 | |
|      * ResourceUtilizationController constructor.
 | |
|      */
 | |
|     public function __construct(private Repository $cache, private DaemonServerRepository $repository)
 | |
|     {
 | |
|         parent::__construct();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * View resources
 | |
|      *
 | |
|      * Return the current resource utilization for a server. This value is cached for up to
 | |
|      * 20 seconds at a time to ensure that repeated requests to this endpoint do not cause
 | |
|      * a flood of unnecessary API calls.
 | |
|      *
 | |
|      * @return array<array-key, mixed>
 | |
|      *
 | |
|      * @throws ConnectionException
 | |
|      */
 | |
|     public function __invoke(GetServerRequest $request, Server $server): array
 | |
|     {
 | |
|         $key = "resources:$server->uuid";
 | |
|         $stats = $this->cache->remember($key, Carbon::now()->addSeconds(20), function () use ($server) {
 | |
|             return $this->repository->setServer($server)->getDetails();
 | |
|         });
 | |
| 
 | |
|         return $this->fractal->item($stats)
 | |
|             ->transformWith($this->getTransformer(StatsTransformer::class))
 | |
|             ->toArray();
 | |
|     }
 | |
| }
 |