feat: add web dashboard for TTS service monitoring

新增了可视化的服务监控面板,添加了/health接口的扩展信息展示,将根路径重定向到监控面板页面,包含服务状态、请求统计、错误记录等监控数据
This commit is contained in:
sun
2026-05-20 19:48:55 +08:00
parent f3197338d4
commit 45591a4e3a
2 changed files with 501 additions and 1 deletions
+7 -1
View File
@@ -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")