mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
feat: Add system information dashboard to admin panel
This commit is contained in:
parent
7c3faa922f
commit
4de44c6476
2 changed files with 177 additions and 0 deletions
146
admin/index.php
146
admin/index.php
|
@ -132,6 +132,19 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
|
||||||
$users_per_day = $total_users;
|
$users_per_day = $total_users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get database version info
|
||||||
|
$database_version = $lang['NOT_AVAILABLE'];
|
||||||
|
$sql = 'SELECT VERSION() as version';
|
||||||
|
$result = DB()->sql_query($sql);
|
||||||
|
$row = DB()->sql_fetchrow($result);
|
||||||
|
if (isset($row['version'])) {
|
||||||
|
$database_version = $row['version'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get disk space information & memory info
|
||||||
|
$getDiskSpaceInfo = getDiskSpaceInfo();
|
||||||
|
$getMemoryInfo = getMemoryInfo();
|
||||||
|
|
||||||
$template->assign_vars([
|
$template->assign_vars([
|
||||||
'NUMBER_OF_POSTS' => commify($total_posts),
|
'NUMBER_OF_POSTS' => commify($total_posts),
|
||||||
'NUMBER_OF_TOPICS' => commify($total_topics),
|
'NUMBER_OF_TOPICS' => commify($total_topics),
|
||||||
|
@ -141,6 +154,15 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
|
||||||
'TOPICS_PER_DAY' => $topics_per_day,
|
'TOPICS_PER_DAY' => $topics_per_day,
|
||||||
'USERS_PER_DAY' => $users_per_day,
|
'USERS_PER_DAY' => $users_per_day,
|
||||||
'AVATAR_DIR_SIZE' => $avatar_dir_size,
|
'AVATAR_DIR_SIZE' => $avatar_dir_size,
|
||||||
|
// System info
|
||||||
|
'SERVER_OS' => htmlCHR(php_uname('s') . ' ' . php_uname('r') . ' ' . php_uname('m')),
|
||||||
|
'SERVER_PHP_VER' => htmlCHR(phpversion()),
|
||||||
|
'SERVER_PHP_SAPI' => htmlCHR(php_sapi_name()),
|
||||||
|
'SERVER_PHP_MEM_LIMIT' => htmlCHR(ini_get('memory_limit')),
|
||||||
|
'SERVER_PHP_MAX_EXECUTION_TIME' => htmlCHR(ini_get('max_execution_time')),
|
||||||
|
'SERVER_DATABASE_VER' => htmlCHR($database_version),
|
||||||
|
'SERVER_DISK_SPACE_INFO' => htmlCHR(sprintf('%s (used: %s | free: %s)', $getDiskSpaceInfo['total'], $getDiskSpaceInfo['used'], $getDiskSpaceInfo['free'])),
|
||||||
|
'SERVER_MEMORY_INFO' => htmlCHR(sprintf('%s (used: %s | free: %s)', $getMemoryInfo['system_total'], $getMemoryInfo['system_used'], $getMemoryInfo['system_free'])),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isset($_GET['users_online'])) {
|
if (isset($_GET['users_online'])) {
|
||||||
|
@ -225,4 +247,128 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
|
||||||
print_page('index.tpl', 'admin', 'no_header');
|
print_page('index.tpl', 'admin', 'no_header');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get disk space information
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return array|string[]
|
||||||
|
*/
|
||||||
|
function getDiskSpaceInfo(string $path = BB_ROOT): array
|
||||||
|
{
|
||||||
|
global $lang;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$bytes_total = disk_total_space($path);
|
||||||
|
$bytes_free = disk_free_space($path);
|
||||||
|
|
||||||
|
if ($bytes_total === false || $bytes_free === false) {
|
||||||
|
return [
|
||||||
|
'total' => $lang['NOT_AVAILABLE'],
|
||||||
|
'free' => $lang['NOT_AVAILABLE'],
|
||||||
|
'used' => $lang['NOT_AVAILABLE'],
|
||||||
|
'percent_used' => $lang['NOT_AVAILABLE']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$bytes_used = $bytes_total - $bytes_free;
|
||||||
|
$percent_used = ($bytes_total > 0) ? round(($bytes_used / $bytes_total) * 100, 2) : 0;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'total' => humn_size($bytes_total),
|
||||||
|
'free' => humn_size($bytes_free),
|
||||||
|
'used' => humn_size($bytes_used),
|
||||||
|
'percent_used' => $percent_used,
|
||||||
|
'path' => realpath($path)
|
||||||
|
];
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return [
|
||||||
|
'total' => 'Ошибка: ' . $e->getMessage(),
|
||||||
|
'free' => 'Ошибка: ' . $e->getMessage(),
|
||||||
|
'used' => 'Ошибка: ' . $e->getMessage(),
|
||||||
|
'percent_used' => 'Ошибка: ' . $e->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get memory info
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function getMemoryInfo(): array
|
||||||
|
{
|
||||||
|
global $lang;
|
||||||
|
|
||||||
|
$memInfo = [];
|
||||||
|
|
||||||
|
$memInfo['php_memory_usage'] = humn_size(memory_get_usage(true));
|
||||||
|
$memInfo['php_memory_peak'] = humn_size(memory_get_peak_usage(true));
|
||||||
|
$memInfo['php_memory_limit'] = ini_get('memory_limit');
|
||||||
|
|
||||||
|
// Попытка получить системную информацию о памяти
|
||||||
|
if (function_exists('sys_getloadavg') && is_readable('/proc/meminfo')) {
|
||||||
|
$meminfo = file_get_contents('/proc/meminfo');
|
||||||
|
if ($meminfo) {
|
||||||
|
$lines = explode("\n", $meminfo);
|
||||||
|
$memdata = [];
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
if (preg_match('/^(\w+):\s*(\d+)\s*kB/', $line, $matches)) {
|
||||||
|
$memdata[$matches[1]] = $matches[2] * 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($memdata['MemTotal'])) {
|
||||||
|
$total = $memdata['MemTotal'];
|
||||||
|
$free = $memdata['MemFree'] ?? 0;
|
||||||
|
$available = $memdata['MemAvailable'] ?? $free;
|
||||||
|
$buffers = $memdata['Buffers'] ?? 0;
|
||||||
|
$cached = $memdata['Cached'] ?? 0;
|
||||||
|
|
||||||
|
$used = $total - $available;
|
||||||
|
$percent_used = ($total > 0) ? round(($used / $total) * 100, 2) : 0;
|
||||||
|
|
||||||
|
$memInfo['system_total'] = humn_size($total);
|
||||||
|
$memInfo['system_free'] = humn_size($free);
|
||||||
|
$memInfo['system_available'] = humn_size($available);
|
||||||
|
$memInfo['system_used'] = humn_size($used);
|
||||||
|
$memInfo['system_buffers'] = humn_size($buffers);
|
||||||
|
$memInfo['system_cached'] = humn_size($cached);
|
||||||
|
$memInfo['system_percent_used'] = $percent_used;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (stripos(PHP_OS, 'win') === 0) {
|
||||||
|
try {
|
||||||
|
$output = shell_exec('wmic OS get TotalVisibleMemorySize,FreePhysicalMemory /value 2>nul');
|
||||||
|
if ($output) {
|
||||||
|
preg_match('/FreePhysicalMemory=(\d+)/', $output, $free_matches);
|
||||||
|
preg_match('/TotalVisibleMemorySize=(\d+)/', $output, $total_matches);
|
||||||
|
|
||||||
|
if (!empty($free_matches[1]) && !empty($total_matches[1])) {
|
||||||
|
$total = $total_matches[1] * 1024;
|
||||||
|
$free = $free_matches[1] * 1024;
|
||||||
|
$used = $total - $free;
|
||||||
|
$percent_used = ($total > 0) ? round(($used / $total) * 100, 2) : 0;
|
||||||
|
|
||||||
|
$memInfo['system_total'] = humn_size($total);
|
||||||
|
$memInfo['system_free'] = humn_size($free);
|
||||||
|
$memInfo['system_used'] = humn_size($used);
|
||||||
|
$memInfo['system_percent_used'] = $percent_used;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($memInfo['system_total'])) {
|
||||||
|
$memInfo['system_total'] = $lang['NOT_AVAILABLE'];
|
||||||
|
$memInfo['system_free'] = $lang['NOT_AVAILABLE'];
|
||||||
|
$memInfo['system_used'] = $lang['NOT_AVAILABLE'];
|
||||||
|
$memInfo['system_percent_used'] = $lang['NOT_AVAILABLE'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $memInfo;
|
||||||
|
}
|
||||||
|
|
||||||
print_page('index.tpl', 'admin');
|
print_page('index.tpl', 'admin');
|
||||||
|
|
|
@ -167,6 +167,37 @@
|
||||||
</table>
|
</table>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
<table class="forumline">
|
||||||
|
<tr>
|
||||||
|
<th colspan="4">System information</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="row1" nowrap="nowrap">OS:</td>
|
||||||
|
<td class="row2"><b>{SERVER_OS}</b></td>
|
||||||
|
<td class="row1" nowrap="nowrap">PHP:</td>
|
||||||
|
<td class="row2"><b>{SERVER_PHP_VER}</b></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="row1" nowrap="nowrap">Database:</td>
|
||||||
|
<td class="row2"><b>{SERVER_DATABASE_VER}</b></td>
|
||||||
|
<td class="row1" nowrap="nowrap">SAPI:</td>
|
||||||
|
<td class="row2"><b>{SERVER_PHP_SAPI}</b></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="row1" nowrap="nowrap">Disk space info:</td>
|
||||||
|
<td class="row2"><b>{SERVER_DISK_SPACE_INFO}</b></td>
|
||||||
|
<td class="row1" nowrap="nowrap">Memory limit:</td>
|
||||||
|
<td class="row2"><b>{SERVER_PHP_MEM_LIMIT}</b></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="row1" nowrap="nowrap">Memory info:</td>
|
||||||
|
<td class="row2"><b>{SERVER_MEMORY_INFO}</b></td>
|
||||||
|
<td class="row1" nowrap="nowrap">Max execution time:</td>
|
||||||
|
<td class="row2"><b>{SERVER_PHP_MAX_EXECUTION_TIME}</b></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
<table class="forumline">
|
<table class="forumline">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="4">{L_FORUM_STATS}</th>
|
<th colspan="4">{L_FORUM_STATS}</th>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue