Merge pull request #1130 from stanjg/feature/stats-page

Added a statistics page to monitor the panel usage
This commit is contained in:
Dane Everitt 2018-05-31 22:56:58 -07:00 committed by GitHub
commit fd8d7c3571
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 576 additions and 0 deletions

View file

@ -296,4 +296,14 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
return $this->getBuilder()->getConnection()->statement($statement, $bindings);
}
/**
* Get the amount of entries in the database
*
* @return int
*/
public function count(): int
{
return $this->getBuilder()->count();
}
}

View file

@ -56,6 +56,33 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
})->toArray();
}
/**
* Return the usage stats for a single node.
*
* @param \Pterodactyl\Models\Node $node
* @return array
*/
public function getUsageStatsRaw(Node $node): array
{
$stats = $this->getBuilder()->select(
$this->getBuilder()->raw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
)->join('servers', 'servers.node_id', '=', 'nodes.id')->where('node_id', $node->id)->first();
return collect(['disk' => $stats->sum_disk, 'memory' => $stats->sum_memory])->mapWithKeys(function ($value, $key) use ($node) {
$maxUsage = $node->{$key};
if ($node->{$key . '_overallocate'} > 0) {
$maxUsage = $node->{$key} * (1 + ($node->{$key . '_overallocate'} / 100));
}
return [
$key => [
'value' => $value,
'max' => $maxUsage,
],
];
})->toArray();
}
/**
* Return all available nodes with a searchable interface.
*

View file

@ -328,4 +328,14 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
$this->app->make(SubuserRepository::class)->getBuilder()->select('server_id')->where('user_id', $user)
)->pluck('id')->all();
}
/**
* Get the amount of servers that are suspended
*
* @return int
*/
public function getSuspendedServersCount(): int
{
return $this->getBuilder()->where('suspended', true)->count();
}
}