feat: MySQL/PG 实时指标采集 + 版本检测修复 + 密码加密存储

- 新增 getMySQLMetrics(): SHOW GLOBAL STATUS 采集连接数/QPS/延迟/运行时间
- 新增 getPostgresMetrics(): pg_stat_activity 采集活跃连接+运行时间
- 修复 extractVersion(): 支持 Redis 'version: 7.4.9, mode: standalone' 格式(逗号截断)
- CreateInstance/UpdateInstance: 创建/更新时自动加密密码(enc: 前缀)
- InstanceMetrics handler: MySQL/PG 分别调用专属 metrics 函数
This commit is contained in:
logan committed 2026-05-31 00:15:18 +08:00
1 parent 433e7e2909
commit 31db229d70
2 files changed
+185 -4

No files matched your search

+20 -1
View File
@@ -64,6 +64,13 @@ func CreateInstance(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"detail": err.Error()})
return
}
// Encrypt password before storing
if instance.Password != "" {
encPw, err := encryptPassword(instance.Password)
if err == nil {
instance.Password = "enc:" + encPw
}
}
if err := model.DB.Create(&instance).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": err.Error()})
return
@@ -105,6 +112,13 @@ func UpdateInstance(c *gin.Context) {
if pw, ok := input["password"].(string); ok && pw == "******" {
delete(input, "password")
}
// Encrypt password if provided and not masked
if pw, ok := input["password"].(string); ok && pw != "" {
encPw, err := encryptPassword(pw)
if err == nil {
input["password"] = "enc:" + encPw
}
}
if err := model.DB.Model(&instance).Updates(input).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": err.Error()})
@@ -191,8 +205,13 @@ func InstanceMetrics(c *gin.Context) {
case "redis":
metrics := getRedisMetrics(&instance)
c.JSON(http.StatusOK, metrics)
case "mysql":
metrics := getMySQLMetrics(&instance)
c.JSON(http.StatusOK, metrics)
case "postgresql", "postgres", "pg":
metrics := getPostgresMetrics(&instance)
c.JSON(http.StatusOK, metrics)
default:
// For MySQL/PG: return basic status
c.JSON(http.StatusOK, gin.H{
"status": "online",
"version": instance.Version,