diff --git a/config-loader/internal/models/config.go b/config-loader/internal/models/config.go index 4a61cfa..2db177d 100644 --- a/config-loader/internal/models/config.go +++ b/config-loader/internal/models/config.go @@ -71,3 +71,33 @@ func (r *Rule) ToJSONRule() JSONRule { Args: args, } } + +// func init() { +// // 计算一个Rule结构体的大小 +// ruleSize := int(unsafe.Sizeof(Rule{})) + +// // 计算ConfigData结构体的总大小 +// configSize := int(unsafe.Sizeof(ConfigData{})) + +// // 转换为MB的函数 +// toMB := func(bytes int) float64 { +// return float64(bytes) / 1024 / 1024 +// } + +// // 验证共享内存大小是否足够 +// if configSize > constants.ShmSize { +// panic(fmt.Sprintf("Shared memory size is too small to hold ConfigData structure. "+ +// "Required size: %d bytes (%.2f MB), "+ +// "Current size: %d bytes (%.2f MB)", +// configSize, toMB(configSize), +// constants.ShmSize, toMB(constants.ShmSize))) +// } + +// // 打印详细信息便于调试 +// log.Printf("Memory allocation details:") +// log.Printf("- Single Rule size: %d bytes (%.2f MB)", ruleSize, toMB(ruleSize)) +// log.Printf("- Total ConfigData size: %d bytes (%.2f MB)", configSize, toMB(configSize)) +// log.Printf("- Shared memory size: %d bytes (%.2f MB)", constants.ShmSize, toMB(constants.ShmSize)) +// log.Printf("- Available space: %d bytes (%.2f MB)", +// constants.ShmSize-configSize, toMB(constants.ShmSize-configSize)) +// } diff --git a/shared/pkg/constants/constants.go b/shared/pkg/constants/constants.go index 4913a55..cddaa05 100644 --- a/shared/pkg/constants/constants.go +++ b/shared/pkg/constants/constants.go @@ -1,12 +1,12 @@ package constants const ( - MaxRules = 256 // 最大规则数量 - MaxArgs = 64 // 每条规则的最大参数数量 - MaxRuleCmdLength = 256 // 规则命令的最大长度 - MaxRuleTypeLength = 32 // 规则类型的最大长度 - MaxRuleMsgLength = 256 // 规则消息的最大长度 - MaxArgLength = 128 // 单个参数的最大长度 + MaxRules = 512 + 64 + 32 // 最大规则数量(尽可能把空间占用完) + MaxArgs = 128 // 每条规则的最大参数数量 + MaxRuleCmdLength = 256 // 规则命令的最大长度(可执行文件路径受到ext4限制,为255) + MaxRuleTypeLength = 32 // 规则类型的最大长度(warn,error,info) + MaxRuleMsgLength = 4096 // 规则消息的最大长度(可以很复杂的内容,长一点) + MaxArgLength = 256 + 128 // 单个参数的最大长度(最大可能就是255的文件路径加上前缀) ShmKey = 0x78945 // 共享内存的键值 ShmSize = 32 * 1024 * 1024 // 共享内存的大小(字节)