<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>服务器监控系统</title>
    <style>
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.5;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            padding: 20px;
        }
        
        /* 头部样式 */
        .header {
            text-align: center;
            padding: 20px 0;
            border-bottom: 2px solid #eaeaea;
            margin-bottom: 30px;
        }
        
        .header h1 {
            color: #2c3e50;
            margin-bottom: 10px;
            font-size: 24px;
        }
        
        .header p {
            color: #7f8c8d;
            font-size: 14px;
        }
        
        /* 状态标签 */
        .status-tag {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            margin: 0 5px;
        }
        
        .status-online {
            background-color: #d5f4e6;
            color: #27ae60;
        }
        
        .status-warning {
            background-color: #fef9e7;
            color: #f39c12;
        }
        
        .status-danger {
            background-color: #fdeaea;
            color: #e74c3c;
        }
        
        /* 监控卡片网格 */
        .monitor-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 20px;
            margin-bottom: 30px;
        }
        
        @media (max-width: 768px) {
            .monitor-grid {
                grid-template-columns: 1fr;
            }
        }
        
        /* 卡片样式 */
        .card {
            background: #fff;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
            padding: 20px;
            transition: all 0.3s ease;
        }
        
        .card:hover {
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            transform: translateY(-2px);
        }
        
        .card-title {
            font-size: 18px;
            color: #34495e;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
            display: flex;
            align-items: center;
        }
        
        .card-title i {
            margin-right: 10px;
            font-size: 20px;
        }
        
        /* 数据行样式 */
        .data-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px dashed #f0f0f0;
        }
        
        .data-row:last-child {
            border-bottom: none;
        }
        
        .data-label {
            color: #666;
            font-size: 14px;
        }
        
        .data-value {
            font-weight: bold;
            color: #2c3e50;
            font-size: 16px;
        }
        
        /* 进度条样式 */
        .progress-container {
            width: 100%;
            height: 10px;
            background-color: #ecf0f1;
            border-radius: 5px;
            margin: 15px 0;
            overflow: hidden;
        }
        
        .progress-bar {
            height: 100%;
            border-radius: 5px;
            transition: width 0.5s ease;
        }
        
        .cpu-progress {
            background: linear-gradient(90deg, #ff7675, #e17055);
        }
        
        .memory-progress {
            background: linear-gradient(90deg, #74b9ff, #0984e3);
        }
        
        .disk-progress {
            background: linear-gradient(90deg, #55efc4, #00b894);
        }
        
        /* 使用率显示 */
        .usage-value {
            font-size: 28px;
            font-weight: bold;
            text-align: center;
            margin: 15px 0;
        }
        
        .cpu-value {
            color: #e17055;
        }
        
        .memory-value {
            color: #0984e3;
        }
        
        .disk-value {
            color: #00b894;
        }
        
        /* 状态颜色 */
        .status-safe {
            color: #27ae60;
        }
        
        .status-warn {
            color: #f39c12;
        }
        
        .status-danger {
            color: #e74c3c;
        }
        
        /* 系统信息卡片 */
        .system-info {
            background: #f8f9fa;
            border-left: 4px solid #3498db;
        }
        
        .system-info .card-title {
            color: #3498db;
        }
        
        /* 页脚 */
        .footer {
            text-align: center;
            padding: 20px;
            margin-top: 30px;
            border-top: 1px solid #eee;
            color: #7f8c8d;
            font-size: 14px;
        }
        
        .update-time {
            color: #95a5a6;
            font-style: italic;
            margin-top: 10px;
        }
        
        /* 图标样式 */
        .icon {
            display: inline-block;
            width: 24px;
            text-align: center;
            margin-right: 8px;
        }
        
        /* 数据状态判断 */
        .data-status {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: normal;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 头部 -->
        <div class="header">
            <h1>🖥️ 服务器监控面板</h1>
            <p>实时监控服务器资源使用情况</p>
            <div style="margin-top: 10px;">
                <span class="status-tag status-online">运行中</span>
                <span class="status-tag">主机: {{ data.hostname }}</span>
                <span class="status-tag">更新时间: {{ data.timestamp }}</span>
            </div>
        </div>
        
        <!-- 监控数据网格 -->
        <div class="monitor-grid">
            <!-- CPU 使用率 -->
            <div class="card">
                <div class="card-title">
                    <span class="icon">💻</span> CPU 使用情况
                </div>
                <div class="usage-value cpu-value">
                    {{ data.cpu_percent|round(1) }}%
                </div>
                <div class="progress-container">
                    <div class="progress-bar cpu-progress" style="width: {{ data.cpu_percent }}%"></div>
                </div>
                <div class="data-row">
                    <span class="data-label">CPU 核心数:</span>
                    <span class="data-value">{{ data.cpu_count }}</span>
                </div>
                <div class="data-row">
                    <span class="data-label">当前状态:</span>
                    <span class="data-value">
                        {% if data.cpu_percent > 80 %}
                            <span class="status-danger">高负载</span>
                        {% elif data.cpu_percent > 50 %}
                            <span class="status-warn">中等负载</span>
                        {% else %}
                            <span class="status-safe">正常</span>
                        {% endif %}
                    </span>
                </div>
            </div>
            
            <!-- 内存使用率 -->
            <div class="card">
                <div class="card-title">
                    <span class="icon">🧠</span> 内存使用情况
                </div>
                <div class="usage-value memory-value">
                    {{ data.memory_percent|round(1) }}%
                </div>
                <div class="progress-container">
                    <div class="progress-bar memory-progress" style="width: {{ data.memory_percent }}%"></div>
                </div>
                <div class="data-row">
                    <span class="data-label">总内存:</span>
                    <span class="data-value">{{ data.mem_total_gb }} GB</span>
                </div>
                <div class="data-row">
                    <span class="data-label">可用内存:</span>
                    <span class="data-value">{{ data.mem_available_gb }} GB</span>
                </div>
                <div class="data-row">
                    <span class="data-label">内存状态:</span>
                    <span class="data-value">
                        {% if data.memory_percent > 85 %}
                            <span class="status-danger">紧张</span>
                        {% elif data.memory_percent > 70 %}
                            <span class="status-warn">注意</span>
                        {% else %}
                            <span class="status-safe">充足</span>
                        {% endif %}
                    </span>
                </div>
            </div>
            
            <!-- 磁盘使用率 -->
            <div class="card">
                <div class="card-title">
                    <span class="icon">💾</span> 磁盘使用情况
                </div>
                <div class="usage-value disk-value">
                    {{ data.disk_percent|round(1) }}%
                </div>
                <div class="progress-container">
                    <div class="progress-bar disk-progress" style="width: {{ data.disk_percent }}%"></div>
                </div>
                <div class="data-row">
                    <span class="data-label">磁盘总空间:</span>
                    <span class="data-value">{{ data.disk_total_gb }} GB</span>
                </div>
                <div class="data-row">
                    <span class="data-label">可用空间:</span>
                    <span class="data-value">{{ data.disk_free_gb }} GB</span>
                </div>
                <div class="data-row">
                    <span class="data-label">磁盘状态:</span>
                    <span class="data-value">
                        {% if data.disk_percent > 90 %}
                            <span class="status-danger">即将满</span>
                        {% elif data.disk_percent > 75 %}
                            <span class="status-warn">注意</span>
                        {% else %}
                            <span class="status-safe">正常</span>
                        {% endif %}
                    </span>
                </div>
            </div>
            
            <!-- 系统信息 -->
            <div class="card system-info">
                <div class="card-title">
                    <span class="icon">⚙️</span> 系统信息
                </div>
                <div class="data-row">
                    <span class="data-label">主机名:</span>
                    <span class="data-value">{{ data.hostname }}</span>
                </div>
                <div class="data-row">
                    <span class="data-label">系统时间:</span>
                    <span class="data-value">{{ data.timestamp }}</span>
                </div>
                <div class="data-row">
                    <span class="data-label">系统启动:</span>
                    <span class="data-value">{{ data.boot_time }}</span>
                </div>
                <div class="data-row">
                    <span class="data-label">内核版本:</span>
                    <span class="data-value">{{ data.kernel_version }}</span>
                </div>
                <div class="data-row">
                    <span class="data-label">运行状态:</span>
                    <span class="data-value status-safe">正常</span>
                </div>
            </div>
        </div>
        
        <!-- 统计数据 -->
        <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 30px 0;">
            <div style="background: #f8f9fa; padding: 15px; border-radius: 6px; text-align: center;">
                <div style="font-size: 12px; color: #7f8c8d;">CPU平均负载</div>
                <div style="font-size: 18px; font-weight: bold; color: #2c3e50;">
                    {{ data.cpu_percent|round(1) }}%
                </div>
            </div>
            <div style="background: #f8f9fa; padding: 15px; border-radius: 6px; text-align: center;">
                <div style="font-size: 12px; color: #7f8c8d;">内存使用率</div>
                <div style="font-size: 18px; font-weight: bold; color: #2c3e50;">
                    {{ data.memory_percent|round(1) }}%
                </div>
            </div>
            <div style="background: #f8f9fa; padding: 15px; border-radius: 6px; text-align: center;">
                <div style="font-size: 12px; color: #7f8c8d;">磁盘使用率</div>
                <div style="font-size: 18px; font-weight: bold; color: #2c3e50;">
                    {{ data.disk_percent|round(1) }}%
                </div>
            </div>
        </div>
        
        <!-- 页脚 -->
        <div class="footer">
            <p>Server Monitor v1.0 | 监控系统</p>
            <div class="update-time">
                最后更新: {{ data.timestamp }} | 数据每5分钟自动刷新
            </div>
            <div style="margin-top: 10px;">
                <a href="/api/data" style="color: #3498db; text-decoration: none; margin-right: 15px;">查看JSON数据</a>
                <a href="/" style="color: #3498db; text-decoration: none;">刷新页面</a>
            </div>
        </div>
    </div>
</body>
</html>
