Files
aiops/backend/model/custom_dashboard.go
T
attacker f725ca7cac feat(monitor): F4 自定义监控仪表盘 — mock 桩改真实 CRUD + PromQL 查询渲染
后端:
- 新增 model/custom_dashboard.go (monitor_custom_dashboards 表)
- 新增 controller/custom_dashboard.go (CRUD + 设默认, 6 路由)
- routes.go 注册 /custom-dashboards 路由组
- database.go AutoMigrate 注册 CustomDashboard

前端:
- grafana.ts: dashboardApi 从 mock 返回空改为真实 HTTP 调用
- metrics.ts: prometheusProxyApi 新增 query/queryRange 方法
- GrafanaPanelContent.tsx: 从随机 mock 数据改为执行 PromQL 查询
  + Recharts LineChart 渲染 graph 类型
  + SVG gauge 渲染 gauge 类型
  + 数值卡片渲染 stat 类型
  + 表格渲染 table 类型
  + 30s 自动刷新 + loading/error 状态
  + 自动发现默认 Prometheus 数据源
- GrafanaDashboard.tsx: 传递 datasourceUrl 到 GrafanaPanelContent

验证: go build✅ npm build✅ 17/17 集成测试通过 E2E CRUD 全通过
2026-06-27 23:28:04 +08:00

32 lines
1.5 KiB
Go

package model
import (
"time"
)
// CustomDashboard 自定义监控仪表盘(面板配置存 JSON) // Logan.Li
type CustomDashboard struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:仪表盘名称" json:"name"`
Description string `gorm:"type:varchar(512);comment:描述" json:"description"`
Datasource string `gorm:"type:varchar(32);default:'prometheus';comment:数据源类型" json:"datasource"`
DatasourceURL string `gorm:"type:varchar(512);comment:数据源URL(留空则用默认Prometheus)" json:"datasource_url"`
// Panels 存储面板配置 JSON 数组: [{id,title,type,query,width,height,x,y,options}]
Panels string `gorm:"type:longtext;comment:面板配置JSON" json:"panels"`
// Tags 标签(JSON 数组字符串)
Tags string `gorm:"type:varchar(512);comment:标签JSON" json:"tags,omitempty"`
// 归属
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by"`
IsDefault bool `gorm:"default:false;index;comment:是否默认仪表盘" json:"is_default"`
IsFavorite bool `gorm:"default:false;comment:是否收藏" json:"is_favorite"`
// 时间戳
CreatedAt time.Time `gorm:"not null;index;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
}
// TableName 指定表名
func (CustomDashboard) TableName() string {
return "monitor_custom_dashboards"
}