✨ feat(database): 完善请求日志体系并为全表补充时间字段
- request_log 新增 user_agent 列(含旧表 ALTER 迁移)及 ip/status 索引,记录解码后的明文 query(含 key,不脱敏) - 请求日志批量写入改为多值 INSERT 单次往返,替代事务逐条 Exec - 新增按本地时区分天聚合查询,状态页展示今日请求量与近 7 天请求趋势(峰值日高亮) - 新增 TZ 时区支持:.env 配置 TZ 后日志时间戳与状态页全部时间统一生效,二进制内嵌 tzdata 保证容器可用 - 五张表统一补齐 created_at/updated_at 字段,启动时自动补列并按业务时间回填旧行 - device_pool 的 device_header 增加唯一约束;audio_cache 写入改为 UPSERT 修复同 key 重复报错 - 状态页"最近请求"新增 UA 列与限流状态显示;config.yaml 暴露 rate_limit_qps 配置并默认启用请求日志
This commit is contained in:
1 parent
1a4997e031
commit
126a96d744
12 files changed
+277
-55
No files matched your search
@@ -68,9 +68,17 @@ func HandleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
"Status": e.Status,
|
||||
"IsErr": e.Status >= 400,
|
||||
"Duration": fmt.Sprintf("%dms", e.DurationMs),
|
||||
"UA": truncateStr(e.UserAgent, 60),
|
||||
})
|
||||
}
|
||||
|
||||
// 近 7 天请求量(日志未启用时为空);最后一天即今日
|
||||
var todayCount int64
|
||||
daily := fqapi.GetDailyRequestStats(7)
|
||||
if n := len(daily); n > 0 {
|
||||
todayCount = daily[n-1].Count
|
||||
}
|
||||
|
||||
statusTmpl.Execute(w, map[string]interface{}{
|
||||
"NowTime": time.Now().Format("2006-01-02 15:04:05"),
|
||||
"Uptime": uptimeStr,
|
||||
@@ -94,6 +102,9 @@ func HandleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
"StatAudio": stats["audio"],
|
||||
"StatVideo": stats["video"],
|
||||
"StatCategory": stats["category"],
|
||||
"TodayCount": todayCount,
|
||||
"DailyStats": daily,
|
||||
"RateLimit": getRateLimitDesc(),
|
||||
"CacheCount": getDBCacheCount(),
|
||||
"CacheStatus": getCacheStatus(),
|
||||
"CleanupStatus": getCleanupStatus(),
|
||||
@@ -110,6 +121,15 @@ func truncateStr(s string, n int) string {
|
||||
return s[:n] + "…"
|
||||
}
|
||||
|
||||
// getRateLimitDesc 当前每 IP 限流描述(server.rate_limit_qps,0=不限制)
|
||||
func getRateLimitDesc() string {
|
||||
cfg := config.GetAppConfig()
|
||||
if cfg == nil || cfg.Server.RateLimitQPS <= 0 {
|
||||
return "未启用"
|
||||
}
|
||||
return fmt.Sprintf("%.0f QPS/IP", cfg.Server.RateLimitQPS)
|
||||
}
|
||||
|
||||
// getCacheStatus 获取缓存状态
|
||||
func getCacheStatus() string {
|
||||
cfg := config.GetConfig()
|
||||
|
||||
Reference in new issue
Block a user