forked from AzuraCast/AzuraCast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine Cpu/Network/Memory stats into
ServerStats
, have the admin A…
…PI endpoint return a documented OpenAPI return format, then use that on the frontend.
- Loading branch information
1 parent
6cfa6c9
commit d92ff13
Showing
30 changed files
with
1,187 additions
and
866 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity\Api\Admin\ServerStats; | ||
|
||
use OpenApi\Attributes as OA; | ||
|
||
#[OA\Schema( | ||
schema: 'Api_Admin_ServerStats_CpuStats', | ||
type: 'object' | ||
)] | ||
final class CpuStats | ||
{ | ||
public function __construct( | ||
#[OA\Property] | ||
public CpuStatsSection $total, | ||
#[OA\Property(items: new OA\Items(ref: '#/components/schemas/Api_Admin_ServerStats_CpuStatsSection'))] | ||
public array $cores, | ||
#[OA\Property(items: new OA\Items(type: 'integer', format: 'int64'))] | ||
public array $load | ||
) { | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
backend/src/Entity/Api/Admin/ServerStats/CpuStatsSection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity\Api\Admin\ServerStats; | ||
|
||
use App\Service\ServerStats\CpuData; | ||
use OpenApi\Attributes as OA; | ||
|
||
#[OA\Schema( | ||
schema: 'Api_Admin_ServerStats_CpuStatsSection', | ||
type: 'object' | ||
)] | ||
final class CpuStatsSection | ||
{ | ||
#[OA\Property] | ||
public string $name; | ||
|
||
#[OA\Property] | ||
public string $usage; | ||
|
||
#[OA\Property] | ||
public string $idle; | ||
|
||
#[OA\Property] | ||
public string $io_wait; | ||
|
||
#[OA\Property] | ||
public string $steal; | ||
|
||
public static function fromCpuData(CpuData $cpuData): self | ||
{ | ||
$return = new self(); | ||
$return->name = $cpuData->name; | ||
$return->usage = (string)$cpuData->getUsage(); | ||
$return->idle = (string)$cpuData->getIdle(); | ||
$return->io_wait = (string)$cpuData->getIoWait(); | ||
$return->steal = (string)$cpuData->getSteal(); | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity\Api\Admin\ServerStats; | ||
|
||
use App\Radio\Quota; | ||
use App\Service\ServerStats\MemoryData; | ||
use OpenApi\Attributes as OA; | ||
|
||
#[OA\Schema( | ||
schema: 'Api_Admin_ServerStats_MemoryStats', | ||
type: 'object' | ||
)] | ||
final class MemoryStats | ||
{ | ||
#[OA\Property] | ||
public string $total_bytes; | ||
|
||
#[OA\Property] | ||
public string $total_readable; | ||
|
||
#[OA\Property] | ||
public string $free_bytes; | ||
|
||
#[OA\Property] | ||
public string $free_readable; | ||
|
||
#[OA\Property] | ||
public string $buffers_bytes; | ||
|
||
#[OA\Property] | ||
public string $buffers_readable; | ||
|
||
#[OA\Property] | ||
public string $cached_bytes; | ||
|
||
#[OA\Property] | ||
public string $cached_readable; | ||
|
||
#[OA\Property] | ||
public string $sReclaimable_bytes; | ||
|
||
#[OA\Property] | ||
public string $sReclaimable_readable; | ||
|
||
#[OA\Property] | ||
public string $shmem_bytes; | ||
|
||
#[OA\Property] | ||
public string $shmem_readable; | ||
|
||
#[OA\Property] | ||
public string $used_bytes; | ||
|
||
#[OA\Property] | ||
public string $used_readable; | ||
|
||
public static function fromMemory(MemoryData $memoryStats): self | ||
{ | ||
$record = new self(); | ||
|
||
$record->total_bytes = (string)$memoryStats->memTotal; | ||
$record->total_readable = Quota::getReadableSize($memoryStats->memTotal, 2); | ||
|
||
$record->free_bytes = (string)$memoryStats->memFree; | ||
$record->free_readable = Quota::getReadableSize($memoryStats->memFree, 2); | ||
|
||
$record->buffers_bytes = (string)$memoryStats->buffers; | ||
$record->buffers_readable = Quota::getReadableSize($memoryStats->buffers, 2); | ||
|
||
$record->cached_bytes = (string)$memoryStats->cached; | ||
$record->cached_readable = Quota::getReadableSize($memoryStats->cached, 2); | ||
|
||
$record->sReclaimable_bytes = (string)$memoryStats->sReclaimable; | ||
$record->sReclaimable_readable = Quota::getReadableSize($memoryStats->sReclaimable, 2); | ||
|
||
$record->shmem_bytes = (string)$memoryStats->shmem; | ||
$record->shmem_readable = Quota::getReadableSize($memoryStats->shmem, 2); | ||
|
||
$usedBytes = $memoryStats->getUsedMemory(); | ||
$record->used_bytes = (string)$usedBytes; | ||
$record->used_readable = Quota::getReadableSize($usedBytes, 2); | ||
|
||
return $record; | ||
} | ||
} |
Oops, something went wrong.