diff --git a/health.html b/health.html new file mode 100644 index 0000000..aac9f4c --- /dev/null +++ b/health.html @@ -0,0 +1,494 @@ + + + + + + TTS 服务监控 + + + + + +
+
+

TTS 服务监控

+
{{ healthData.service || 'Loading...' }} - {{ healthData.version || '' }}
+ +
+ +
+ {{ error }} +
+ +
+
+
+
+ + 服务状态 +
+
{{ healthData.status === 'ok' ? '正常运行' : '配置错误' }}
+
运行时长: {{ formatUptime(healthData.uptime) }}
+
+ +
+
+ + 请求统计 +
+
+
+
{{ healthData.api_stats?.total_requests || 0 }}
+
总请求数
+
+
+
{{ healthData.api_stats?.successful_requests || 0 }}
+
成功
+
+
+
{{ healthData.api_stats?.failed_requests || 0 }}
+
失败
+
+
+
+ +
+
+ + 错误率 +
+
+ {{ healthData.api_stats?.error_rate_percent || '0' }}% +
+
平均响应: {{ healthData.api_stats?.avg_response_time_ms || '0' }} ms
+
+
+ +
+
+
+ + 配置状态 +
+
+ 环境变量 + + {{ healthData.config_status?.all_required_vars_set ? '已配置' : '未配置' }} + +
+
+ Resource ID + {{ healthData.config_status?.resource_id || '-' }} +
+
+ 发音人 + {{ healthData.config_status?.speaker || '-' }} +
+
+ 启动时间 + {{ healthData.start_time || '-' }} +
+
+ +
+
+ + 内存使用 +
+
+
+
{{ formatBytes(healthData.memory?.heap_alloc) }}
+
Heap Alloc
+
+
+
{{ formatBytes(healthData.memory?.heap_inuse) }}
+
Heap Inuse
+
+
+
{{ healthData.memory?.goroutines || 0 }}
+
Goroutines
+
+
+
+ +
+
+ + 响应时间趋势 +
+
+
+
+
+
+
+ +
+
+ + 错误记录 ({{ recentErrors.length }}) +
+
+ 暂无错误记录 +
+
+
+
{{ err }}
+
+
+
+
+ +
+ 加载中... +
+
+ + + + \ No newline at end of file diff --git a/tts_server.go b/tts_server.go index d3e7f07..d053444 100644 --- a/tts_server.go +++ b/tts_server.go @@ -652,11 +652,14 @@ func healthHandler(w http.ResponseWriter, r *http.Request) { }, "errors": map[string]interface{}{ "recent_errors_count": len(lastErrors), + "recent_errors": lastErrors, }, "config_status": map[string]interface{}{ "all_required_vars_set": allEnvVarsSet, "config_error": ttsConfigErr != nil, "config_error_message": fmt.Sprintf("%v", ttsConfigErr), + "resource_id": ttsConfig.ResourceId, + "speaker": ttsConfig.Speaker, }, } @@ -730,8 +733,11 @@ func main() { router.HandleFunc("/v1/audio/speech", openaiTTSHandler).Methods("POST", "OPTIONS") router.HandleFunc("/health", healthHandler).Methods("GET") + router.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "health.html") + }).Methods("GET") router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/health", http.StatusFound) + http.Redirect(w, r, "/dashboard", http.StatusFound) }).Methods("GET") port := os.Getenv("PORT")