feat(config): 添加指标保存间隔和最大文件数的默认值处理

- 在配置解析中新增 MetricsSaveInterval 和 MetricsMaxFiles 字段
- 在前端页面为指标配置添加默认值(15分钟间隔,10个文件)
- 更新配置解析逻辑以支持新的指标相关配置
This commit is contained in:
wood chen 2025-03-09 05:47:41 +08:00
parent 015aa6bc15
commit 4276709b3f
2 changed files with 19 additions and 5 deletions

View File

@ -37,6 +37,8 @@ func (c *Config) UnmarshalJSON(data []byte) error {
type TempConfig struct { type TempConfig struct {
MAP map[string]json.RawMessage `json:"MAP"` MAP map[string]json.RawMessage `json:"MAP"`
Compression CompressionConfig `json:"Compression"` Compression CompressionConfig `json:"Compression"`
MetricsSaveInterval int `json:"MetricsSaveInterval"`
MetricsMaxFiles int `json:"MetricsMaxFiles"`
} }
var temp TempConfig var temp TempConfig
@ -47,6 +49,11 @@ func (c *Config) UnmarshalJSON(data []byte) error {
// 初始化 MAP // 初始化 MAP
c.MAP = make(map[string]PathConfig) c.MAP = make(map[string]PathConfig)
// 复制其他字段
c.Compression = temp.Compression
c.MetricsSaveInterval = temp.MetricsSaveInterval
c.MetricsMaxFiles = temp.MetricsMaxFiles
// 处理每个路径配置 // 处理每个路径配置
for key, raw := range temp.MAP { for key, raw := range temp.MAP {
// 尝试作为字符串解析 // 尝试作为字符串解析
@ -69,9 +76,6 @@ func (c *Config) UnmarshalJSON(data []byte) error {
c.MAP[key] = pathConfig c.MAP[key] = pathConfig
} }
// 复制其他字段
c.Compression = temp.Compression
return nil return nil
} }

View File

@ -124,6 +124,16 @@ export default function ConfigPage() {
} }
const data = await response.json() const data = await response.json()
// 设置默认值
if (data.MetricsSaveInterval === undefined || data.MetricsSaveInterval === 0) {
data.MetricsSaveInterval = 15; // 默认15分钟
}
if (data.MetricsMaxFiles === undefined || data.MetricsMaxFiles === 0) {
data.MetricsMaxFiles = 10; // 默认10个文件
}
setConfig(data) setConfig(data)
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : "获取配置失败" const message = error instanceof Error ? error.message : "获取配置失败"