Files
Volcano-Engine-TTS-UI/health.html
T
sun f75a8461d1 chore: 移除文件开头多余的UTF-8 BOM头
修复多个文件中存在的隐藏BOM字符问题,包括go.mod、README.md、health.html和.env.example,同时更新go.sum文件的校验和
2026-08-15 15:02:00 +08:00

224 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TTS 服务监控</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh; color: #e0e0e0; padding: 20px;
}
#app { max-width: 1200px; margin: 0 auto; }
.header { text-align: center; margin-bottom: 30px; }
.header h1 {
font-size: 2em;
background: linear-gradient(90deg, #00d4ff, #7b2ff7);
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
margin-bottom: 10px;
}
.header .version { color: #888; font-size: 0.9em; }
.actions { display: flex; justify-content: center; gap: 12px; margin-top: 15px; flex-wrap: wrap; }
.btn {
background: linear-gradient(90deg, #00d4ff, #7b2ff7);
border: none; color: white; padding: 10px 24px; border-radius: 8px;
cursor: pointer; font-size: 14px; text-decoration: none;
transition: opacity 0.3s; display: inline-block;
}
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary {
background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.2);
}
.grid {
display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px; margin-bottom: 20px;
}
.card {
background: rgba(255,255,255,0.05); border-radius: 16px; padding: 24px;
backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.1);
}
.card-title {
font-size: 14px; color: #888; text-transform: uppercase; letter-spacing: 1px;
margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}
.card-title .dot { width: 8px; height: 8px; border-radius: 50%; background: #00d4ff; }
.card-title .dot.error { background: #ff4757; }
.stat-value {
font-size: 2em; font-weight: bold;
background: linear-gradient(90deg, #00d4ff, #7b2ff7);
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.stat-label { color: #888; font-size: 14px; margin-top: 5px; }
.info-row {
display: flex; justify-content: space-between;
padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.info-row:last-child { border-bottom: none; }
.info-label { color: #888; }
.info-value { color: #fff; font-family: 'Monaco', 'Menlo', monospace; }
.info-value.success { color: #2ed573; }
.info-value.error { color: #ff4757; }
.memory-stat { display: flex; justify-content: space-around; text-align: center; }
.memory-stat .value { font-size: 1.2em; font-weight: bold; color: #00d4ff; }
.memory-stat .label { font-size: 12px; color: #888; margin-top: 4px; }
.error-box {
background: rgba(255,71,87,0.1); border: 1px solid rgba(255,71,87,0.3);
border-radius: 12px; padding: 20px; color: #ff4757; text-align: center;
}
.loading { text-align: center; padding: 40px; color: #888; }
.metrics-frame {
width: 100%; height: 600px; border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px; background: #0e0e1a; margin-top: 20px;
}
</style>
</head>
<body>
<div id="app">
<div class="header">
<h1>TTS 服务监控</h1>
<div class="version">{{ healthData.service || 'Loading...' }} - {{ healthData.version || '' }}</div>
<div class="actions">
<button class="btn" @click="fetchHealth(true)" :disabled="loading">
{{ loading ? '刷新中...' : '刷新状态' }}
</button>
<a class="btn secondary" href="/metrics" target="_blank">查看 Prometheus 指标</a>
</div>
</div>
<div v-if="error" class="error-box">{{ error }}</div>
<div v-if="healthData.status">
<div class="grid">
<div class="card">
<div class="card-title">
<span class="dot" :class="{ error: healthData.status !== 'ok' }"></span>
服务状态
</div>
<div class="stat-value">{{ healthData.status === 'ok' ? '正常运行' : '配置错误' }}</div>
<div class="stat-label">运行时长: {{ formatUptime(healthData.uptime) }}</div>
</div>
<div class="card">
<div class="card-title"><span class="dot"></span>配置状态</div>
<div class="info-row">
<span class="info-label">环境变量</span>
<span class="info-value" :class="healthData.config_status?.all_required_vars_set ? 'success' : 'error'">
{{ healthData.config_status?.all_required_vars_set ? '已配置' : '未配置' }}
</span>
</div>
<div class="info-row">
<span class="info-label">启动时间</span>
<span class="info-value">{{ healthData.start_time || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">详细指标</span>
<a class="info-value" href="/metrics" target="_blank" style="color:#00d4ff">/metrics</a>
</div>
</div>
<div class="card">
<div class="card-title"><span class="dot"></span>内存使用</div>
<div class="memory-stat">
<div>
<div class="value">{{ formatBytes(healthData.memory?.heap_alloc) }}</div>
<div class="label">Heap Alloc</div>
</div>
<div>
<div class="value">{{ formatBytes(healthData.memory?.heap_inuse) }}</div>
<div class="label">Heap Inuse</div>
</div>
<div>
<div class="value">{{ healthData.memory?.goroutines || 0 }}</div>
<div class="label">Goroutines</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-title"><span class="dot"></span>指标预览 (Prometheus 文本格式)</div>
<iframe class="metrics-frame" src="/metrics"></iframe>
</div>
</div>
<div v-if="loading && !healthData.status" class="loading">加载中...</div>
</div>
<script>
const { createApp, ref, onMounted } = Vue;
createApp({
setup() {
const healthData = ref({});
const loading = ref(false);
const error = ref(null);
const deepUpdate = (target, source) => {
for (const key of Object.keys(source)) {
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
if (!target[key]) target[key] = {};
deepUpdate(target[key], source[key]);
} else {
target[key] = source[key];
}
}
};
const fetchHealth = async (showLoading = false) => {
if (showLoading) loading.value = true;
try {
const response = await axios.get('/health');
deepUpdate(healthData.value, response.data);
error.value = null;
} catch (e) {
if (e.response && e.response.data) {
deepUpdate(healthData.value, e.response.data);
if (e.response.status === 503) {
error.value = '服务配置异常,请检查环境变量配置';
} else {
error.value = '服务异常: ' + (e.message || '未知错误');
}
} else {
error.value = '无法获取服务状态: ' + (e.message || '未知错误');
}
} finally {
loading.value = false;
}
};
const formatBytes = (bytes) => {
if (!bytes) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toFixed(1) + ' ' + sizes[i];
};
const formatUptime = (seconds) => {
if (!seconds) return '-';
const s = parseInt(seconds);
const d = Math.floor(s / 86400);
const h = Math.floor((s % 86400) / 3600);
const m = Math.floor((s % 3600) / 60);
if (d > 0) return `${d}天 ${h}小时`;
if (h > 0) return `${h}小时 ${m}分钟`;
return `${m}分钟`;
};
onMounted(() => {
fetchHealth(true);
setInterval(() => fetchHealth(false), 10000);
});
return { healthData, loading, error, fetchHealth, formatBytes, formatUptime };
}
}).mount('#app');
</script>
</body>
</html>