Merge pull request #569 from ok236449/Admin-overview-per-node-info
Show info about each node separately on admin overview
This commit is contained in:
commit
a4d83a75d9
|
@ -14,11 +14,6 @@ use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class Pterodactyl
|
class Pterodactyl
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @description per_page option to pull more than the default 50 from pterodactyl
|
|
||||||
*/
|
|
||||||
public const PER_PAGE = 200;
|
|
||||||
|
|
||||||
//TODO: Extend error handling (maybe logger for more errors when debugging)
|
//TODO: Extend error handling (maybe logger for more errors when debugging)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +68,7 @@ class Pterodactyl
|
||||||
public static function getEggs(Nest $nest)
|
public static function getEggs(Nest $nest)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = self::client()->get("/application/nests/{$nest->id}/eggs?include=nest,variables&per_page=" . self::PER_PAGE);
|
$response = self::client()->get("/application/nests/{$nest->id}/eggs?include=nest,variables&per_page=" . config("SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT"));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw self::getException($e->getMessage());
|
throw self::getException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -88,7 +83,7 @@ class Pterodactyl
|
||||||
public static function getNodes()
|
public static function getNodes()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = self::client()->get('/application/nodes?per_page=' . self::PER_PAGE);
|
$response = self::client()->get('/application/nodes?per_page=' . config("SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT"));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw self::getException($e->getMessage());
|
throw self::getException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -115,7 +110,7 @@ class Pterodactyl
|
||||||
|
|
||||||
public static function getServers() {
|
public static function getServers() {
|
||||||
try {
|
try {
|
||||||
$response = self::client()->get('/application/servers');
|
$response = self::client()->get('/application/servers?per_page=' . config("SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT"));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw self::getException($e->getMessage());
|
throw self::getException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -130,7 +125,7 @@ class Pterodactyl
|
||||||
public static function getNests()
|
public static function getNests()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = self::client()->get('/application/nests?per_page=' . self::PER_PAGE);
|
$response = self::client()->get('/application/nests?per_page=' . config("SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT"));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw self::getException($e->getMessage());
|
throw self::getException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -145,7 +140,7 @@ class Pterodactyl
|
||||||
public static function getLocations()
|
public static function getLocations()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = self::client()->get('/application/locations?per_page=' . self::PER_PAGE);
|
$response = self::client()->get('/application/locations?per_page=' . config("SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT"));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw self::getException($e->getMessage());
|
throw self::getException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public function checkPteroClientkey(){
|
||||||
"server-limit-purchase" => "required|min:0|integer",
|
"server-limit-purchase" => "required|min:0|integer",
|
||||||
"pterodactyl-api-key" => "required|string",
|
"pterodactyl-api-key" => "required|string",
|
||||||
"pterodactyl-url" => "required|string",
|
"pterodactyl-url" => "required|string",
|
||||||
|
"per-page-limit" => "required|min:0|integer",
|
||||||
"pterodactyl-admin-api-key" => "required|string",
|
"pterodactyl-admin-api-key" => "required|string",
|
||||||
"enable-upgrades" => "string",
|
"enable-upgrades" => "string",
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ public function checkPteroClientkey(){
|
||||||
"SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE" => "server-limit-purchase",
|
"SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE" => "server-limit-purchase",
|
||||||
"SETTINGS::MISC:PHPMYADMIN:URL" => "phpmyadmin-url",
|
"SETTINGS::MISC:PHPMYADMIN:URL" => "phpmyadmin-url",
|
||||||
"SETTINGS::SYSTEM:PTERODACTYL:URL" => "pterodactyl-url",
|
"SETTINGS::SYSTEM:PTERODACTYL:URL" => "pterodactyl-url",
|
||||||
|
'SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT' => "per-page-limit",
|
||||||
"SETTINGS::SYSTEM:PTERODACTYL:TOKEN" => "pterodactyl-api-key",
|
"SETTINGS::SYSTEM:PTERODACTYL:TOKEN" => "pterodactyl-api-key",
|
||||||
"SETTINGS::SYSTEM:ENABLE_LOGIN_LOGO" => "enable-login-logo",
|
"SETTINGS::SYSTEM:ENABLE_LOGIN_LOGO" => "enable-login-logo",
|
||||||
"SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN" => "pterodactyl-admin-api-key",
|
"SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN" => "pterodactyl-admin-api-key",
|
||||||
|
|
|
@ -11,6 +11,8 @@ use App\Models\Payment;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use App\Classes\Pterodactyl;
|
||||||
|
use App\Models\Product;
|
||||||
|
|
||||||
class OverViewController extends Controller
|
class OverViewController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -18,36 +20,71 @@ class OverViewController extends Controller
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$userCount = Cache::remember('user:count', self::TTL, function () {
|
$counters = Cache::remember('counters', self::TTL, function () {
|
||||||
return User::query()->count();
|
$output = collect();
|
||||||
});
|
$output->put('users', User::query()->count());
|
||||||
|
$output->put('credits', number_format(User::query()->where("role","!=","admin")->sum('credits'), 2, '.', ''));
|
||||||
|
$output->put('payments', Payment::query()->count());
|
||||||
|
$output->put('eggs', Egg::query()->count());
|
||||||
|
$output->put('nests', Nest::query()->count());
|
||||||
|
$output->put('locations', Location::query()->count());
|
||||||
|
|
||||||
$creditCount = Cache::remember('credit:count', self::TTL, function () {
|
$output->put('servers', collect());
|
||||||
return User::query()->where("role","!=","admin")->sum('credits');
|
$output['servers']->active = 0;
|
||||||
});
|
$output['servers']->total = 0;
|
||||||
|
$output->put('earnings', collect());
|
||||||
|
$output['earnings']->active = 0;
|
||||||
|
$output['earnings']->total = 0;
|
||||||
|
$output->put('totalUsagePercent', 0);
|
||||||
|
|
||||||
$paymentCount = Cache::remember('payment:count', self::TTL, function () {
|
return $output;
|
||||||
return Payment::query()->count();
|
|
||||||
});
|
|
||||||
|
|
||||||
$serverCount = Cache::remember('server:count', self::TTL, function () {
|
|
||||||
return Server::query()->count();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$lastEgg = Egg::query()->latest('updated_at')->first();
|
$lastEgg = Egg::query()->latest('updated_at')->first();
|
||||||
$syncLastUpdate = $lastEgg ? $lastEgg->updated_at->isoFormat('LLL') : __('unknown');
|
$syncLastUpdate = $lastEgg ? $lastEgg->updated_at->isoFormat('LLL') : __('unknown');
|
||||||
|
|
||||||
return view('admin.overview.index', [
|
$nodes = Cache::remember('nodes', self::TTL, function() use($counters){
|
||||||
'serverCount' => $serverCount,
|
$output = collect();
|
||||||
'userCount' => $userCount,
|
foreach($nodes = Node::query()->get() as $node){ //gets all node information and prepares the structure
|
||||||
'paymentCount' => $paymentCount,
|
$nodeId = $node['id'];
|
||||||
'creditCount' => number_format($creditCount, 2, '.', ''),
|
$output->put($nodeId, collect());
|
||||||
|
$output[$nodeId]->name = $node['name'];
|
||||||
|
$node = Pterodactyl::getNode($nodeId);
|
||||||
|
$output[$nodeId]->usagePercent = round(max($node['allocated_resources']['memory']/($node['memory']*($node['memory_overallocate']+100)/100), $node['allocated_resources']['disk']/($node['disk']*($node['disk_overallocate']+100)/100))*100, 2);
|
||||||
|
$counters['totalUsagePercent'] += $output[$nodeId]->usagePercent;
|
||||||
|
|
||||||
'locationCount' => Location::query()->count(),
|
$output[$nodeId]->totalServers = 0;
|
||||||
'nodeCount' => Node::query()->count(),
|
$output[$nodeId]->activeServers = 0;
|
||||||
'nestCount' => Nest::query()->count(),
|
$output[$nodeId]->totalEarnings = 0;
|
||||||
'eggCount' => Egg::query()->count(),
|
$output[$nodeId]->activeEarnings = 0;
|
||||||
'syncLastUpdate' => $syncLastUpdate
|
}
|
||||||
|
$counters['totalUsagePercent'] = round($counters['totalUsagePercent']/$nodes->count(), 2);
|
||||||
|
|
||||||
|
foreach(Pterodactyl::getServers() as $server){ //gets all servers from Pterodactyl and calculates total of credit usage for each node separately + total
|
||||||
|
$nodeId = $server['attributes']['node'];
|
||||||
|
|
||||||
|
if($CPServer = Server::query()->where('pterodactyl_id', $server['attributes']['id'])->first()){
|
||||||
|
$prize = Product::query()->where('id', $CPServer->product_id)->first()->price;
|
||||||
|
if (!$CPServer->suspended){
|
||||||
|
$counters['earnings']->active += $prize;
|
||||||
|
$counters['servers']->active ++;
|
||||||
|
$output[$nodeId]->activeEarnings += $prize;
|
||||||
|
$output[$nodeId]->activeServers ++;
|
||||||
|
}
|
||||||
|
$counters['earnings']->total += $prize;
|
||||||
|
$counters['servers']->total ++;
|
||||||
|
$output[$nodeId]->totalEarnings += $prize;
|
||||||
|
$output[$nodeId]->totalServers ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
});
|
||||||
|
|
||||||
|
return view('admin.overview.index', [
|
||||||
|
'counters' => $counters,
|
||||||
|
'nodes' => $nodes,
|
||||||
|
'syncLastUpdate' => $syncLastUpdate,
|
||||||
|
'perPageLimit' => ($counters['servers']->total != Server::query()->count())?true:false
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,6 +378,13 @@ class SettingsSeeder extends Seeder
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => 'The URL to your Pterodactyl Panel. Must not end with a / '
|
'description' => 'The URL to your Pterodactyl Panel. Must not end with a / '
|
||||||
]);
|
]);
|
||||||
|
Settings::firstOrCreate([
|
||||||
|
'key' => 'SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT',
|
||||||
|
], [
|
||||||
|
'value' => 200,
|
||||||
|
'type' => 'integer',
|
||||||
|
'description' => 'The Pterodactyl API perPage limit. It is necessary to set it higher than your server count.'
|
||||||
|
]);
|
||||||
Settings::firstOrCreate([
|
Settings::firstOrCreate([
|
||||||
'key' => 'SETTINGS::MISC:PHPMYADMIN:URL',
|
'key' => 'SETTINGS::MISC:PHPMYADMIN:URL',
|
||||||
], [
|
], [
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
|
|
||||||
<div class="info-box-content">
|
<div class="info-box-content">
|
||||||
<span class="info-box-text">{{__('Servers')}}</span>
|
<span class="info-box-text">{{__('Servers')}}</span>
|
||||||
<span class="info-box-number">{{$serverCount}}</span>
|
<span class="info-box-number">{{$counters['servers']->total}}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.info-box-content -->
|
<!-- /.info-box-content -->
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
<div class="info-box-content">
|
<div class="info-box-content">
|
||||||
<span class="info-box-text">{{__('Users')}}</span>
|
<span class="info-box-text">{{__('Users')}}</span>
|
||||||
<span class="info-box-number">{{$userCount}}</span>
|
<span class="info-box-number">{{$counters['users']}}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.info-box-content -->
|
<!-- /.info-box-content -->
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
|
|
||||||
<div class="info-box-content">
|
<div class="info-box-content">
|
||||||
<span class="info-box-text">{{__('Total')}} {{CREDITS_DISPLAY_NAME}}</span>
|
<span class="info-box-text">{{__('Total')}} {{CREDITS_DISPLAY_NAME}}</span>
|
||||||
<span class="info-box-number">{{$creditCount}}</span>
|
<span class="info-box-number">{{$counters['credits']}}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.info-box-content -->
|
<!-- /.info-box-content -->
|
||||||
</div>
|
</div>
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
<div class="info-box-content">
|
<div class="info-box-content">
|
||||||
<span class="info-box-text">{{__('Payments')}}</span>
|
<span class="info-box-text">{{__('Payments')}}</span>
|
||||||
<span class="info-box-number">{{$paymentCount}}</span>
|
<span class="info-box-number">{{$counters['payments']}}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.info-box-content -->
|
<!-- /.info-box-content -->
|
||||||
</div>
|
</div>
|
||||||
|
@ -121,19 +121,19 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{__('Locations')}}</td>
|
<td>{{__('Locations')}}</td>
|
||||||
<td>{{$locationCount}}</td>
|
<td>{{$counters['locations']}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{__('Nodes')}}</td>
|
<td>{{__('Nodes')}}</td>
|
||||||
<td>{{$nodeCount}}</td>
|
<td>{{$nodes->count()}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{__('Nests')}}</td>
|
<td>{{__('Nests')}}</td>
|
||||||
<td>{{$nestCount}}</td>
|
<td>{{$counters['nests']}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{__('Eggs')}}</td>
|
<td>{{__('Eggs')}}</td>
|
||||||
<td>{{$eggCount}}</td>
|
<td>{{$counters['eggs']}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -142,8 +142,6 @@
|
||||||
<span><i class="fas fa-sync mr-2"></i>{{__('Last updated :date', ['date' => $syncLastUpdate])}}</span>
|
<span><i class="fas fa-sync mr-2"></i>{{__('Last updated :date', ['date' => $syncLastUpdate])}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="col-md-6">
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
|
@ -160,6 +158,59 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div class="card-title ">
|
||||||
|
<span><i class="fas fa-file-invoice-dollar mr-2"></i>{{__('Individual nodes')}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body py-1">
|
||||||
|
@if ($perPageLimit)
|
||||||
|
<div class="alert alert-danger m-2">
|
||||||
|
<h5><i class="icon fas fa-exclamation-circle"></i>{{ __('Error!') }}</h5>
|
||||||
|
<p class="">
|
||||||
|
{{ __('You reached the Pterodactyl perPage limit. Please make sure to set it higher than your server count.') }}<br>
|
||||||
|
{{ __('You can do that in settings.') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{{__('ID')}}</th>
|
||||||
|
<th>{{__('Node')}}</th>
|
||||||
|
<th>{{__('Server count')}}</th>
|
||||||
|
<th>{{__('Resource usage')}}</th>
|
||||||
|
<th>{{CREDITS_DISPLAY_NAME . ' ' . __('Usage')}}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($nodes as $nodeID => $node)
|
||||||
|
<tr>
|
||||||
|
<td>{{$nodeID}}</td>
|
||||||
|
<td>{{$node->name}}</td>
|
||||||
|
<td>{{$node->activeServers}}/{{$node->totalServers}}</td>
|
||||||
|
<td>{{$node->usagePercent}}%</td>
|
||||||
|
<td>{{$node->activeEarnings}}/{{$node->totalEarnings}}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2"><span style="float: right; font-weight: 700">{{__('Total')}} ({{__('active')}}/{{__('total')}}):</span></td>
|
||||||
|
<td>{{$counters['servers']->active}}/{{$counters['servers']->total}}</td>
|
||||||
|
<td>{{$counters['totalUsagePercent']}}%</td>
|
||||||
|
<td>{{$counters['earnings']->active}}/{{$counters['earnings']->total}}</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- END CUSTOM CONTENT -->
|
<!-- END CUSTOM CONTENT -->
|
||||||
|
|
|
@ -70,6 +70,17 @@
|
||||||
value="{{ config('SETTINGS::SYSTEM:PTERODACTYL:URL') }}"
|
value="{{ config('SETTINGS::SYSTEM:PTERODACTYL:URL') }}"
|
||||||
class="form-control @error('pterodactyl-url') is-invalid @enderror" required>
|
class="form-control @error('pterodactyl-url') is-invalid @enderror" required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="custom-control mb-3 p-0">
|
||||||
|
<div class="col m-0 p-0 d-flex justify-content-between align-items-center">
|
||||||
|
<label for="per-page-limit">{{ __('Pterodactyl API perPage limit') }}</label>
|
||||||
|
<i data-toggle="popover" data-trigger="hover" data-html="true"
|
||||||
|
data-content="{{ __('The Pterodactyl API perPage limit. It is necessary to set it higher than your server count.') }}"
|
||||||
|
class="fas fa-info-circle"></i>
|
||||||
|
</div>
|
||||||
|
<input x-model="per-page-limit" id="per-page-limit" name="per-page-limit" type="number"
|
||||||
|
value="{{ config('SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT') }}"
|
||||||
|
class="form-control @error('per-page-limit') is-invalid @enderror" required>
|
||||||
|
</div>
|
||||||
<div class="custom-control p-0 mb-3">
|
<div class="custom-control p-0 mb-3">
|
||||||
<div class="col m-0 p-0 d-flex justify-content-between align-items-center">
|
<div class="col m-0 p-0 d-flex justify-content-between align-items-center">
|
||||||
<label for="pterodactyl-api-key">{{ __('Pterodactyl API Key') }}</label>
|
<label for="pterodactyl-api-key">{{ __('Pterodactyl API Key') }}</label>
|
||||||
|
|
Loading…
Reference in a new issue