Skip to content

Commit 092fbb0

Browse files
committed
更新页面
1 parent c7e55c1 commit 092fbb0

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

src/admin.php

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -336,28 +336,48 @@ function diagnoseSystem() {
336336

337337
// 获取容器运行时间
338338
function getContainerUptime() {
339-
// 尝试从容器启动时间计算运行时间
340339
$start_time = null;
341340

342-
// 方法1: 从 /proc/1/stat 获取进程启动时间
341+
// 方法1: 从supervisord进程启动时间计算(PID 1)
343342
if (file_exists('/proc/1/stat')) {
344343
$stat_data = file_get_contents('/proc/1/stat');
345344
if ($stat_data) {
346345
$parts = explode(' ', $stat_data);
347346
if (count($parts) >= 22) {
348-
$start_time = intval($parts[21]); // 进程启动时间(时钟滴答)
347+
$start_ticks = intval($parts[21]); // 进程启动时间(时钟滴答)
349348
$clock_ticks = intval(shell_exec('getconf CLK_TCK 2>/dev/null') ?: 100);
350-
$start_time = $start_time / $clock_ticks; // 转换为秒
349+
$start_time = $start_ticks / $clock_ticks; // 转换为秒
351350
}
352351
}
353352
}
354353

355-
// 方法2: 从 /proc/uptime 获取系统运行时间(作为备用)
356-
if (!$start_time && file_exists('/proc/uptime')) {
357-
$uptime_data = file_get_contents('/proc/uptime');
358-
if ($uptime_data) {
359-
$parts = explode(' ', trim($uptime_data));
360-
$start_time = time() - floatval($parts[0]); // 当前时间 - 系统运行时间
354+
// 方法2: 从环境变量获取容器启动时间
355+
if (!$start_time) {
356+
$container_start = getenv('CONTAINER_START_TIME');
357+
if ($container_start) {
358+
$start_time = strtotime($container_start);
359+
}
360+
}
361+
362+
// 方法3: 从Docker inspect获取容器启动时间
363+
if (!$start_time) {
364+
$container_id = getenv('HOSTNAME');
365+
if ($container_id) {
366+
$inspect_output = shell_exec("docker inspect {$container_id} 2>/dev/null | grep -o '\"StartedAt\":\"[^\"]*\"' | cut -d'\"' -f4");
367+
if ($inspect_output) {
368+
$start_time = strtotime(trim($inspect_output));
369+
}
370+
}
371+
}
372+
373+
// 方法4: 从容器内文件创建时间获取
374+
if (!$start_time) {
375+
$container_files = ['/etc/hostname', '/etc/hosts', '/.dockerenv'];
376+
foreach ($container_files as $file) {
377+
if (file_exists($file)) {
378+
$start_time = filemtime($file);
379+
break;
380+
}
361381
}
362382
}
363383

@@ -461,22 +481,18 @@ function getContainerInfo() {
461481

462482
// 获取进程内存占用
463483
function getProcessMemory($process_name) {
464-
// 使用更简单直接的方法获取进程信息
465-
$memory_info = '';
466-
467-
// 直接使用 ps aux 获取所有进程,然后过滤
468-
$all_processes = shell_exec('ps aux 2>/dev/null');
469-
if (!$all_processes) {
484+
// 使用更简单的方法:直接使用 top 命令获取内存信息
485+
$top_output = shell_exec('top -bn1 2>/dev/null');
486+
if (!$top_output) {
470487
return '未运行';
471488
}
472489

473-
$lines = explode("\n", $all_processes);
490+
$lines = explode("\n", $top_output);
474491
$total_memory = 0;
475492
$process_count = 0;
476493

477494
foreach ($lines as $line) {
478495
if (trim($line)) {
479-
// 根据进程名称匹配
480496
$matched = false;
481497

482498
switch ($process_name) {
@@ -503,11 +519,11 @@ function getProcessMemory($process_name) {
503519

504520
if ($matched) {
505521
$parts = preg_split('/\s+/', trim($line));
506-
if (count($parts) >= 6) {
507-
// ps aux 格式: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
508-
$rss = intval($parts[5]); // RSS 在第6列
509-
if ($rss > 0) {
510-
$total_memory += $rss;
522+
if (count($parts) >= 4) {
523+
// top 格式: PID USER %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
524+
$vsz = intval($parts[4]); // VSZ 在第5列
525+
if ($vsz > 0) {
526+
$total_memory += $vsz;
511527
$process_count++;
512528
}
513529
}

src/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h1 class="text-5xl font-bold text-gray-800 mb-4">
5151
PHP-Nginx
5252
</h1>
5353
<p class="text-xl text-gray-600 max-w-2xl mx-auto">
54-
基于 Alpine Linux 的轻量级 PHP 8.4 + Nginx 1.26 + Redis 容器
54+
基于 Alpine Linux 的轻量级 PHP 8.4 + Nginx 1.26 + Redis 7.2.9 容器
5555
</p>
5656
</div>
5757

@@ -125,14 +125,14 @@ <h2 class="text-3xl font-bold text-gray-800 mb-6 text-center">
125125
<i class="fas fa-memory text-blue-600 text-2xl"></i>
126126
</div>
127127
<h3 class="font-bold text-gray-800 mb-2">内存优化</h3>
128-
<p class="text-gray-600 text-sm">PHP 64MB,OPcache 32MB,Redis 64MB</p>
128+
<p class="text-gray-600 text-sm">减少内存占用,提高性能</p>
129129
</div>
130130
<div class="text-center p-4">
131131
<div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
132132
<i class="fas fa-users text-green-600 text-2xl"></i>
133133
</div>
134134
<h3 class="font-bold text-gray-800 mb-2">并发支持</h3>
135-
<p class="text-gray-600 text-sm">最大50个进程,支持50个并发用户</p>
135+
<p class="text-gray-600 text-sm">最大200个进程,支持200个并发用户</p>
136136
</div>
137137
<div class="text-center p-4">
138138
<div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
@@ -149,7 +149,7 @@ <h3 class="font-bold text-gray-800 mb-2">轻量级</h3>
149149
<div class="mt-16 text-center text-gray-500">
150150
<p class="mb-2">
151151
<i class="fas fa-code mr-2"></i>
152-
基于 Alpine Linux 构建的 Docker PHP-FPM 8.4 & Nginx 1.26
152+
基于 Alpine Linux 构建的 Docker PHP-FPM 8.4 & Nginx 1.26 & Redis7.2.9
153153
</p>
154154
<p class="text-sm">
155155
<i class="fas fa-server mr-2"></i>

0 commit comments

Comments
 (0)