systemData = $systemData;
parent::__construct('系统状态', $this->buildContent());
}
/**
* 构建内容
*
* @return string
*/
protected function buildContent(): string
{
$html = '
';
// 服务器信息
$html .= $this->buildServerInfo();
// 性能指标
$html .= $this->buildPerformanceMetrics();
$html .= '
';
return $html;
}
/**
* 构建服务器信息
*
* @return string
*/
protected function buildServerInfo(): string
{
$serverInfo = $this->systemData['server_info'] ?? [];
$html = '';
$html .= '
性能指标
';
// 内存使用率
if (isset($performance['memory'])) {
$memory = $performance['memory'];
$percentage = $memory['percentage'];
$progressClass = $this->getProgressClass($percentage);
$html .= '
';
$html .= '
内存使用率';
$html .= "
";
$html .= "
";
$html .= "
";
$html .= "
{$memory['current']} / {$memory['limit']} ({$percentage}%)";
$html .= '
';
}
// 磁盘使用率
if (isset($performance['disk'])) {
$disk = $performance['disk'];
$percentage = $disk['percentage'];
$progressClass = $this->getProgressClass($percentage);
$html .= '
';
$html .= '
磁盘使用率';
$html .= "
";
$html .= "
";
$html .= "
";
$html .= "
{$disk['used']} / {$disk['total']} ({$percentage}%)";
$html .= '
';
}
// CPU使用率
if (isset($performance['cpu_usage'])) {
$cpuUsage = $performance['cpu_usage'];
$progressClass = $this->getProgressClass($cpuUsage);
$html .= '
';
$html .= '
CPU使用率';
$html .= "
";
$html .= "
";
$html .= "
";
$html .= "
{$cpuUsage}%";
$html .= '
';
}
// 负载平均值
if (isset($performance['load_average'])) {
$load = $performance['load_average'];
$html .= '
';
$html .= '负载平均值
';
$html .= "1分钟: {$load['1min']} | 5分钟: {$load['5min']} | 15分钟: {$load['15min']}";
$html .= '
';
}
// 数据库状态
if (isset($performance['database'])) {
$database = $performance['database'];
$statusClass = $database['status'] === 'healthy' ? 'success' : 'danger';
$statusText = $database['status'] === 'healthy' ? '正常' : '异常';
$html .= '
';
$html .= '数据库状态
';
$html .= "{$statusText}";
if (isset($database['response_time'])) {
$html .= " 响应时间: {$database['response_time']}";
}
$html .= '
';
}
$html .= '
';
return $html;
}
/**
* 根据百分比获取进度条颜色类
*
* @param float $percentage
* @return string
*/
protected function getProgressClass(float $percentage): string
{
if ($percentage < 50) {
return 'success';
} elseif ($percentage < 80) {
return 'warning';
} else {
return 'danger';
}
}
}