fix:归档DB设置最大连接数和最大空闲连接数

This commit is contained in:
tangjiawei
2025-11-24 21:50:00 +08:00
parent 32e751914d
commit 26fb5574c5
7 changed files with 32 additions and 6 deletions

View File

@@ -78,6 +78,10 @@ WeCube通过Open-Monitor监控插件来对资源以及应用的监控及告警
- 监控数据归档
提供程序自动归档监控数据到mysql中自动管理分库分表图表读取适配多处数据整合
**部署建议:** `archive_mysql_tool` 建议在监控集群中单独挑选 1 台(或 1 主 1 备)服务器启用归档任务,其它节点保持 `enable=false`。这样可以避免多机重复归档导致的重复写入和锁竞争,只需确保该节点能访问 Prometheus 与归档 MySQL即可为所有监控实例统一落库。
**配置注意:** 若有多台 `monitor-server` 访问同一归档库,务必确认 `monitor-server/conf/default.json`(以及编排模版 `build/conf/monitor.json`)里的 `archive_mysql.maxOpen/maxIdle` 使用驼峰命名,并结合系统变量设置连接池上限,未配置时系统会回落到 `maxOpen=80 / maxIdle=10 / timeout=60` 的默认值,避免连接池失控。
## 主要功能

View File

@@ -175,9 +175,9 @@
"user": "{{MONITOR_ARCHIVE_MYSQL_USER}}",
"password": "{{MONITOR_ARCHIVE_MYSQL_PWD}}",
"database_prefix": "prometheus_archive_",
"max_open": 100,
"max_idle": 10,
"timeout": 60,
"maxOpen": {{MONITOR_ARCHIVE_READ_MAX_OPEN}},
"maxIdle": {{MONITOR_ARCHIVE_READ_MAX_IDLE}},
"timeout": {{MONITOR_ARCHIVE_READ_TIMEOUT}},
"local_storage_max_day": 30,
"five_min_start_day": 90
},

View File

@@ -120,6 +120,9 @@
<systemParameter name="MONITOR_ARCHIVE_MYSQL_PWD" scopeType="global" defaultValue=""/>
<systemParameter name="MONITOR_ARCHIVE_MYSQL_MAX_OPEN" scopeType="global" defaultValue="150"/>
<systemParameter name="MONITOR_ARCHIVE_MYSQL_MAX_IDLE" scopeType="global" defaultValue="100"/>
<systemParameter name="MONITOR_ARCHIVE_READ_MAX_OPEN" scopeType="global" defaultValue="80"/>
<systemParameter name="MONITOR_ARCHIVE_READ_MAX_IDLE" scopeType="global" defaultValue="10"/>
<systemParameter name="MONITOR_ARCHIVE_READ_TIMEOUT" scopeType="global" defaultValue="60"/>
<systemParameter name="MONITOR_LOG_LEVEL" scopeType="global" defaultValue="info"/>
<systemParameter name="MONITOR_MAIL_DEFAULT_RECEIVER" scopeType="global" defaultValue=""/>
<systemParameter name="MONITOR_ALARM_ALIVE_MAX_DAY" scopeType="global" defaultValue="100"/>

View File

@@ -19,6 +19,9 @@ sed -i "s~{{MONITOR_ARCHIVE_MYSQL_HOST}}~$MONITOR_ARCHIVE_MYSQL_HOST~g" monitor/
sed -i "s~{{MONITOR_ARCHIVE_MYSQL_PORT}}~$MONITOR_ARCHIVE_MYSQL_PORT~g" monitor/conf/default.json
sed -i "s~{{MONITOR_ARCHIVE_MYSQL_USER}}~$MONITOR_ARCHIVE_MYSQL_USER~g" monitor/conf/default.json
sed -i "s~{{MONITOR_ARCHIVE_MYSQL_PWD}}~$MONITOR_ARCHIVE_MYSQL_PWD~g" monitor/conf/default.json
sed -i "s~{{MONITOR_ARCHIVE_READ_MAX_OPEN}}~$MONITOR_ARCHIVE_READ_MAX_OPEN~g" monitor/conf/default.json
sed -i "s~{{MONITOR_ARCHIVE_READ_MAX_IDLE}}~$MONITOR_ARCHIVE_READ_MAX_IDLE~g" monitor/conf/default.json
sed -i "s~{{MONITOR_ARCHIVE_READ_TIMEOUT}}~$MONITOR_ARCHIVE_READ_TIMEOUT~g" monitor/conf/default.json
sed -i "s~{{MONITOR_ALARM_ALIVE_MAX_DAY}}~$MONITOR_ALARM_ALIVE_MAX_DAY~g" monitor/conf/default.json
sed -i "s~{{MONITOR_LOG_LEVEL}}~$MONITOR_LOG_LEVEL~g" monitor/conf/default.json
sed -i "s~{{MONITOR_DB_HOST}}~$MONITOR_DB_HOST~g" archive_mysql_tool/default.json

View File

@@ -175,8 +175,8 @@
"user": "root",
"password": "wecube",
"database_prefix": "prometheus_archive_",
"max_open": 100,
"max_idle": 10,
"maxOpen": 80,
"maxIdle": 10,
"timeout": 60,
"local_storage_max_day": 30,
"five_min_start_day": 90

View File

@@ -14,6 +14,12 @@ import (
"sync"
)
const (
defaultArchiveMysqlMaxOpen = 80
defaultArchiveMysqlMaxIdle = 10
defaultArchiveMysqlTimeout = 60
)
type LogConfig struct {
Level string `json:"level"`
LogDir string `json:"log_dir"`
@@ -271,6 +277,15 @@ func InitConfig(cfg string) {
defer lock.Unlock()
config = &c
if config.ArchiveMysql.MaxOpen <= 0 {
config.ArchiveMysql.MaxOpen = defaultArchiveMysqlMaxOpen
}
if config.ArchiveMysql.MaxIdle <= 0 {
config.ArchiveMysql.MaxIdle = defaultArchiveMysqlMaxIdle
}
if config.ArchiveMysql.Timeout <= 0 {
config.ArchiveMysql.Timeout = defaultArchiveMysqlTimeout
}
config.MonitorAlarmMailEnable = strings.ToLower(config.MonitorAlarmMailEnable)
if config.MonitorAlarmMailEnable == "y" || config.MonitorAlarmMailEnable == "yes" || config.MonitorAlarmMailEnable == "true" {
AlarmMailEnable = true

View File

@@ -92,7 +92,8 @@ func initArchiveDbEngine() {
// 使用驼峰式映射
archiveMysql.SetMapper(core.SnakeMapper{})
archiveDatabase = databaseName
log.Info(nil, log.LOGGER_APP, "Init archive mysql "+archiveDatabase+" success")
log.Info(nil, log.LOGGER_APP, "Init archive mysql "+archiveDatabase+" success", zap.Int("maxIdle", models.Config().ArchiveMysql.MaxIdle),
zap.Int("maxOpen", models.Config().ArchiveMysql.MaxOpen), zap.Int("timeout", models.Config().ArchiveMysql.Timeout))
}
}