feat: Agent采集uptime, 后端持久化kernel/uptime/diskIO, 前端磁盘BPS+IOPS展示

- Agent: system.go 添加 readUptime(), SystemStat 携带 Uptime
- Backend: Server 模型新增 Kernel 字段, ReceiveReport 持久化 kernel+uptime
- Backend: /agent/latest 返回 kernel/uptime/port_info/disk_io_info/disk_total
- Frontend: 磁盘监控改为 BPS+IOPS (4张卡片), 系统信息修复内核/运行时长/监听端口/磁盘容量
- 图表单位从 MB/s 改为 KB/s, 添加 formatBPS 工具函数
This commit is contained in:
attacker committed 2026-06-19 01:10:00 +00:00
1 parent 31c2e338a3
commit 5949ec5d0c
48 files changed
+2182 -956

No files matched your search

+8 -3
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// AgentReport Agent 上报的原始指标数据 // Logan.Li
@@ -25,15 +24,15 @@ type AgentReport struct {
ReportTime time.Time `json:"report_time"` // 上报时间
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentReport) TableName() string {
return "agent_reports"
return "monitor_agent_reports"
}
// AgentLatestResponse Agent 最新状态(含服务器元信息)// Logan.Li
type AgentLatestResponse struct {
ServerID uint `json:"server_id"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
CPUUsage float64 `json:"cpu_usage"`
@@ -42,13 +41,19 @@ type AgentLatestResponse struct {
MemTotal float64 `json:"mem_total"`
MemUsed float64 `json:"mem_used"`
DiskUsage float64 `json:"disk_usage"`
DiskTotal int64 `json:"disk_total"` // 磁盘总容量 GB
DiskInfo string `json:"disk_info"`
PortInfo string `json:"port_info"`
NetInfo string `json:"net_info"`
DiskIOInfo string `json:"disk_io_info"`
ReportTime string `json:"report_time"`
AgentVersion string `json:"agent_version"`
AgentStatus string `json:"agent_status"`
OS string `json:"os"`
Kernel string `json:"kernel"` // 内核版本
Uptime int64 `json:"uptime"` // 运行秒数
Region string `json:"region"`
HasAuth bool `json:"has_auth"` // 是否有 SSH 凭据
}
// AgentReportRequest Agent 上报请求体 // Logan.Li
+3 -7
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// AgentTask Agent 远程任务 // Logan.Li
@@ -22,11 +21,10 @@ type AgentTask struct {
PickedAt *time.Time `json:"picked_at"` // Agent 拉取时间
FinishedAt *time.Time `json:"finished_at"` // 完成时间
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentTask) TableName() string {
return "agent_tasks"
return "monitor_agent_tasks"
}
// AgentRule 告警规则(基于 Agent 数据) // Logan.Li
@@ -42,11 +40,10 @@ type AgentRule struct {
LastTriggered *time.Time `json:"last_triggered"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentRule) TableName() string {
return "agent_rules"
return "monitor_agent_rules"
}
// AgentAlert Agent 告警事件 // Logan.Li
@@ -63,9 +60,8 @@ type AgentAlert struct {
ResolvedAt *time.Time `json:"resolved_at"`
CreatedAt time.Time `gorm:"index" json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentAlert) TableName() string {
return "agent_alerts"
return "monitor_agent_alerts"
}
+4 -7
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// AlertRule 告警规则模型
@@ -22,12 +21,11 @@ type AlertRule struct {
NotifyChannels string `gorm:"type:text" json:"notify_channels"` // JSON
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (AlertRule) TableName() string {
return "alert_rules"
return "monitor_alert_rules"
}
// AlertEvent 告警事件模型
@@ -55,7 +53,7 @@ type AlertEvent struct {
// TableName 表名
func (AlertEvent) TableName() string {
return "alert_events"
return "monitor_alert_events"
}
// NotifyChannel 通知渠道模型
@@ -68,12 +66,11 @@ type NotifyChannel struct {
TestStatus string `gorm:"size:32" json:"test_status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (NotifyChannel) TableName() string {
return "notify_channels"
return "monitor_notify_channels"
}
// MetricData 监控指标数据
@@ -89,7 +86,7 @@ type MetricData struct {
// TableName 表名
func (MetricData) TableName() string {
return "metric_data"
return "monitor_metric_data"
}
// CreateAlertRuleRequest 创建告警规则请求
+11 -6
View File
@@ -94,7 +94,7 @@ type AlertRuleV2 struct {
// TableName 指定表名
func (AlertRuleV2) TableName() string {
return "alert_rules_v2"
return "monitor_alert_rules_v2"
}
// AlertCondition 告警条件定义
@@ -109,6 +109,11 @@ type AlertCondition struct {
Window int `json:"window"` // 条件级聚合窗口
}
// TableName 指定表名
func (AlertCondition) TableName() string {
return "monitor_alert_conditions"
}
// AlertConditionGroup 告警条件组
type AlertConditionGroup struct {
Conditions []AlertCondition `json:"conditions"` // 条件列表
@@ -159,7 +164,7 @@ type AlertNotifyTemplate struct {
// TableName 指定表名
func (AlertNotifyTemplate) TableName() string {
return "alert_notify_templates"
return "monitor_alert_notify_templates"
}
// TemplateVariable 模板变量定义
@@ -209,7 +214,7 @@ type AlertUpgrade struct {
// TableName 指定表名
func (AlertUpgrade) TableName() string {
return "alert_upgrades"
return "monitor_alert_upgrades"
}
// AlertUpgradeRule 告警升级规则
@@ -235,7 +240,7 @@ type AlertUpgradeRecord struct {
// TableName 指定表名
func (AlertUpgradeRecord) TableName() string {
return "alert_upgrade_records"
return "monitor_alert_upgrade_records"
}
// ============================================
@@ -278,7 +283,7 @@ type AlertSilence struct {
// TableName 指定表名
func (AlertSilence) TableName() string {
return "alert_silences"
return "monitor_alert_silences"
}
// AlertSilenceMatcher 静默匹配条件
@@ -349,7 +354,7 @@ type AlertEventV2 struct {
// TableName 指定表名
func (AlertEventV2) TableName() string {
return "alert_events_v2"
return "monitor_alert_events_v2"
}
// AlertRuleV2CreateRequest 告警规则创建请求
+1 -4
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// ApprovalTemplate 审批模板模型
@@ -18,12 +17,11 @@ type ApprovalTemplate struct {
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (ApprovalTemplate) TableName() string {
return "approval_templates"
return "sys_approval_templates"
}
// ApprovalProcess 审批流程模型
@@ -41,7 +39,6 @@ type ApprovalProcess struct {
RejectReason string `gorm:"size:500" json:"reject_reason"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Template *ApprovalTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
+1 -1
View File
@@ -25,7 +25,7 @@ type AuditLog struct {
// TableName 表名
func (AuditLog) TableName() string {
return "audit_logs"
return "sys_audit_logs"
}
// AuditLogQuery 审计日志查询
+3 -7
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// CronJob 定时任务模型
@@ -27,7 +26,6 @@ type CronJob struct {
NotifyOn string `gorm:"size:32;default:failure" json:"notify_on"` // always, failure, success
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Script *Script `json:"script,omitempty"`
@@ -54,12 +52,11 @@ type Script struct {
UpdatedBy uint `json:"updated_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Script) TableName() string {
return "scripts"
return "ops_scripts"
}
// TaskExecution 任务执行记录
@@ -83,7 +80,7 @@ type TaskExecution struct {
// TableName 表名
func (TaskExecution) TableName() string {
return "task_executions"
return "ops_task_executions"
}
// Playbook Ansible Playbook模型
@@ -103,12 +100,11 @@ type Playbook struct {
UpdatedBy uint `json:"updated_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Playbook) TableName() string {
return "playbooks"
return "ops_playbooks"
}
// CreatePlaybookRequest 创建Playbook请求
+2 -5
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// CloudBilling 云账单模型 - 每日成本记录
@@ -21,11 +20,10 @@ type CloudBilling struct {
Description string `gorm:"size:500" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (CloudBilling) TableName() string {
return "cloud_billings"
return "asset_cloud_billings"
}
// BillingAlertRule 账单预警规则
@@ -41,11 +39,10 @@ type BillingAlertRule struct {
LastTriggered *time.Time `json:"last_triggered"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (BillingAlertRule) TableName() string {
return "billing_alert_rules"
return "monitor_billing_alert_rules"
}
// BillingStats 账单统计
+2 -5
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// Pipeline CI/CD流水线模型
@@ -26,12 +25,11 @@ type Pipeline struct {
FailCount int `gorm:"default:0" json:"fail_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Pipeline) TableName() string {
return "pipelines"
return "ops_pipelines"
}
// PipelineRun 流水线运行记录
@@ -81,12 +79,11 @@ type AppRelease struct {
Description string `gorm:"size:500" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (AppRelease) TableName() string {
return "app_releases"
return "deploy_app_releases"
}
// CreatePipelineRequest 创建流水线请求
+47
View File
@@ -0,0 +1,47 @@
package models
import (
"time"
)
// Credential 凭据管理模型(SSH密钥/API Token/密码等统一管理)
type Credential struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"` // 凭据名称
Type string `gorm:"size:32;not null" json:"type"` // ssh_key, api_token, password, access_key
Content string `gorm:"type:text;not null" json:"-"` // AES加密后的内容,API不返回
Description string `gorm:"size:500" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Credential) TableName() string {
return "iam_credentials"
}
// CredentialCreateRequest 创建凭据请求
type CredentialCreateRequest struct {
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required,oneof=ssh_key api_token password access_key"`
Content string `json:"content" binding:"required"` // 明文,后端加密存储
Description string `json:"description"`
}
// CredentialUpdateRequest 更新凭据请求
type CredentialUpdateRequest struct {
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required,oneof=ssh_key api_token password access_key"`
Content string `json:"content"` // 空则不更新内容
Description string `json:"description"`
}
// CredentialListResponse 列表返回(内容脱敏)
type CredentialListResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Preview string `json:"preview"` // 内容预览(前8+后4字符)
Description string `json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
+6 -8
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// K8sCluster K8s集群模型
@@ -29,12 +28,11 @@ type K8sCluster struct {
LastSyncAt *time.Time `json:"last_sync_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (K8sCluster) TableName() string {
return "k8s_clusters"
return "container_clusters"
}
// K8sNode K8s节点模型
@@ -58,7 +56,6 @@ type K8sNode struct {
Labels string `gorm:"type:text" json:"labels"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Cluster *K8sCluster `json:"cluster,omitempty"`
@@ -85,7 +82,6 @@ type K8sPod struct {
Labels string `gorm:"type:text" json:"labels"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Cluster *K8sCluster `json:"cluster,omitempty"`
@@ -110,7 +106,6 @@ type K8sDeployment struct {
Labels string `gorm:"type:text" json:"labels"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Cluster *K8sCluster `json:"cluster,omitempty"`
@@ -135,7 +130,6 @@ type K8sService struct {
Labels string `gorm:"type:text" json:"labels"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Cluster *K8sCluster `json:"cluster,omitempty"`
@@ -159,7 +153,6 @@ type K8sIngress struct {
Labels string `gorm:"type:text" json:"labels"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Cluster *K8sCluster `json:"cluster,omitempty"`
@@ -202,3 +195,8 @@ type TopologyLayout struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 指定表名
func (TopologyLayout) TableName() string {
return "container_topology_layouts"
}
+2 -2
View File
@@ -19,7 +19,7 @@ type LLMConfig struct {
}
// TableName 表名 // Logan.Li
func (LLMConfig) TableName() string { return "llm_configs" }
func (LLMConfig) TableName() string { return "sys_llm_configs" }
// SaveLLMConfigRequest 保存 LLM 配置请求 // Logan.Li
type SaveLLMConfigRequest struct {
@@ -63,4 +63,4 @@ type ChatHistory struct {
}
// TableName 表名 // Logan.Li
func (ChatHistory) TableName() string { return "chat_histories" }
func (ChatHistory) TableName() string { return "ai_chat_histories" }
@@ -0,0 +1,38 @@
package models
import "time"
// MetricsAggregate 指标聚合数据(Redis 热数据 → MySQL 时序聚合)// Logan.Li
// 替代旧名 MetricsKline,OHLC 对监控无意义,改用 max/min/avg/p95
type MetricsAggregate struct {
ID uint `gorm:"primarykey" json:"id"`
Hostname string `gorm:"size:255;index:idx_agg;not null" json:"hostname"`
Metric string `gorm:"size:32;index:idx_agg;not null" json:"metric"` // cpu / mem / load1 / disk / net_rx / net_tx
Interval string `gorm:"size:8;index:idx_agg;not null" json:"interval"` // 1m / 5m / 1h / 6h / 1d
Avg float64 `gorm:"type:decimal(10,2)" json:"avg"`
MaxV float64 `gorm:"column:max_v;type:decimal(10,2)" json:"max"`
MinV float64 `gorm:"column:min_v;type:decimal(10,2)" json:"min"`
P95 float64 `gorm:"type:decimal(10,2)" json:"p95"`
Count int `json:"count"`
BucketTime time.Time `gorm:"index:idx_agg;not null" json:"bucket_time"`
CreatedAt time.Time `json:"created_at"`
}
func (MetricsAggregate) TableName() string {
return "monitor_metrics_aggregate"
}
// AggregateReq 聚合触发请求
type AggregateReq struct {
Hostname string `json:"hostname" binding:"required"`
Metric string `json:"metric" binding:"required"` // cpu / mem / load1
}
// AggregateQueryReq 聚合查询参数
type AggregateQueryReq struct {
Hostname string `form:"hostname" binding:"required"`
Metric string `form:"metric" binding:"required"`
Interval string `form:"interval" binding:"required"`
From string `form:"from" binding:"required"` // RFC3339
To string `form:"to" binding:"required"` // RFC3339
}
-38
View File
@@ -1,38 +0,0 @@
package models
import "time"
// MetricsKline 指标K线聚合数据(由 Redis 热数据聚合到 MySQL)// Logan.Li
type MetricsKline struct {
ID uint `gorm:"primarykey" json:"id"`
Hostname string `gorm:"size:255;index:idx_kline;not null" json:"hostname"`
Metric string `gorm:"size:32;index:idx_kline;not null" json:"metric"` // cpu / mem / load1
Interval string `gorm:"size:8;index:idx_kline;not null" json:"interval"` // 1m / 3m / 1h / 6h / 1d
Open float64 `gorm:"type:decimal(10,2)" json:"open"`
High float64 `gorm:"type:decimal(10,2)" json:"high"`
Low float64 `gorm:"type:decimal(10,2)" json:"low"`
Close float64 `gorm:"type:decimal(10,2)" json:"close"`
Avg float64 `gorm:"type:decimal(10,2)" json:"avg"`
Count int `json:"count"`
BucketTime time.Time `gorm:"index:idx_kline;not null" json:"bucket_time"`
CreatedAt time.Time `json:"created_at"`
}
func (MetricsKline) TableName() string {
return "metrics_klines"
}
// AggregateKlineReq 聚合请求体
type AggregateKlineReq struct {
Hostname string `json:"hostname" binding:"required"`
Metric string `json:"metric" binding:"required"` // cpu / mem / load1
}
// KlineQueryReq K线查询参数(Query 参数)
type KlineQueryReq struct {
Hostname string `form:"hostname" binding:"required"`
Metric string `form:"metric" binding:"required"`
Interval string `form:"interval" binding:"required"`
From string `form:"from" binding:"required"` // RFC3339
To string `form:"to" binding:"required"` // RFC3339
}
+3 -3
View File
@@ -160,7 +160,7 @@ type MetricHistory struct {
}
func (MetricHistory) TableName() string {
return "metric_histories"
return "monitor_metric_histories"
}
// MetricValueQuery 指标值查询参数
@@ -202,7 +202,7 @@ type MetricTag struct {
// TableName 指定表名
func (MetricTag) TableName() string {
return "metric_tags"
return "monitor_metric_tags"
}
// ============================================
@@ -351,5 +351,5 @@ type HostGroup struct {
// TableName 指定表名
func (HostGroup) TableName() string {
return "host_groups"
return "asset_host_groups"
}
+1 -4
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// NavigationGroup 导航分组模型
@@ -18,12 +17,11 @@ type NavigationGroup struct {
LinkCount int `gorm:"default:0" json:"link_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (NavigationGroup) TableName() string {
return "navigation_groups"
return "sys_navigation_groups"
}
// NavigationLink 导航链接模型
@@ -40,7 +38,6 @@ type NavigationLink struct {
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Group *NavigationGroup `json:"group,omitempty"`
+5 -11
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// AnsiblePlaybook Playbook 模型 // Logan.Li
@@ -17,10 +16,9 @@ type AnsiblePlaybook struct {
CreatedBy string `gorm:"size:255" json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AnsiblePlaybook) TableName() string { return "ansible_playbooks" }
func (AnsiblePlaybook) TableName() string { return "ops_ansible_playbooks" }
// AnsibleJob 执行任务记录 // Logan.Li
type AnsibleJob struct {
@@ -37,10 +35,9 @@ type AnsibleJob struct {
CompletedAt *time.Time `json:"completed_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AnsibleJob) TableName() string { return "ansible_jobs" }
func (AnsibleJob) TableName() string { return "ops_ansible_jobs" }
// AnsibleInventory 主机清单 // Logan.Li
type AnsibleInventory struct {
@@ -51,10 +48,9 @@ type AnsibleInventory struct {
CreatedBy string `gorm:"size:255" json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AnsibleInventory) TableName() string { return "ansible_inventories" }
func (AnsibleInventory) TableName() string { return "ops_ansible_inventories" }
// LogSource 日志源 // Logan.Li
type LogSource struct {
@@ -67,10 +63,9 @@ type LogSource struct {
LastSeen *time.Time `json:"last_seen"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (LogSource) TableName() string { return "log_sources" }
func (LogSource) TableName() string { return "sys_log_sources" }
// LogEntry 日志条目 // Logan.Li
type LogEntry struct {
@@ -84,7 +79,6 @@ type LogEntry struct {
TraceID string `gorm:"size:100;index" json:"trace_id"`
Raw string `gorm:"type:text" json:"raw"`
CreatedAt time.Time `json:"created_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (LogEntry) TableName() string { return "log_entries" }
func (LogEntry) TableName() string { return "sys_log_entries" }
@@ -51,7 +51,7 @@ type PrometheusDataSource struct {
// TableName 指定表名
func (PrometheusDataSource) TableName() string {
return "prometheus_datasources"
return "monitor_prometheus_datasources"
}
// ============================================
+1 -3
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// ResourceModel 资源模型 (CMDB 模型定义)
@@ -17,9 +16,8 @@ type ResourceModel struct {
Icon string `gorm:"size:64" json:"icon"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (ResourceModel) TableName() string {
return "resource_models"
return "asset_resource_models"
}
+11 -14
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// Server 服务器模型
@@ -18,6 +17,7 @@ type Server struct {
SSHKey string `gorm:"type:text" json:"-"`
AuthType string `gorm:"size:32;default:password" json:"auth_type"` // password, key
OS string `gorm:"size:64" json:"os"`
Kernel string `gorm:"size:64" json:"kernel"`
OSVersion string `gorm:"size:64" json:"os_version"`
Arch string `gorm:"size:32" json:"arch"`
CPU int `json:"cpu"`
@@ -30,6 +30,7 @@ type Server struct {
Uptime int64 `json:"uptime"` // seconds
AgentVersion string `gorm:"size:32" json:"agent_version"`
AgentStatus string `gorm:"size:32;default:offline" json:"agent_status"` // online, offline
HasAuth bool `gorm:"-" json:"has_auth"` // 是否有认证凭据(密码或SSH密钥) — 不存DB,handler 计算后返回 // Logan.Li
RegionID *uint `json:"region_id"`
CloudID *uint `json:"cloud_id"`
Tags string `gorm:"type:text" json:"tags"` // JSON
@@ -37,7 +38,6 @@ type Server struct {
LastCheckAt *time.Time `json:"last_check_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Region *Region `json:"region,omitempty"`
@@ -46,7 +46,7 @@ type Server struct {
// TableName 表名
func (Server) TableName() string {
return "servers"
return "asset_servers"
}
// Cloud 云平台模型
@@ -60,12 +60,11 @@ type Cloud struct {
Description string `gorm:"size:500" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Cloud) TableName() string {
return "clouds"
return "asset_clouds"
}
// CloudAccount 云账号模型
@@ -82,12 +81,11 @@ type CloudAccount struct {
LastSyncAt *time.Time `json:"last_sync_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (CloudAccount) TableName() string {
return "cloud_accounts"
return "asset_cloud_accounts"
}
// Region 区域模型
@@ -102,12 +100,11 @@ type Region struct {
VPCCount int `gorm:"default:0" json:"vpc_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Region) TableName() string {
return "regions"
return "asset_regions"
}
// Domain 域名模型
@@ -123,12 +120,11 @@ type Domain struct {
SSLExpireDate *time.Time `json:"ssl_expire_date"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Domain) TableName() string {
return "domains"
return "asset_domains"
}
// CreateServerRequest 创建服务器请求
@@ -188,9 +184,10 @@ type BatchServerItem struct {
// BatchCreateServerRequest 批量导入服务器请求 // Logan.Li
type BatchCreateServerRequest struct {
Servers []BatchServerItem `json:"servers"`
RegionID *uint `json:"region_id"`
AuthType string `json:"auth_type"`
Servers []BatchServerItem `json:"servers"`
RegionID *uint `json:"region_id"`
AuthType string `json:"auth_type"`
CredentialID *uint `json:"credential_id"` // 凭据ID,非空则解密后写入每台服务器
}
// BatchCreateResult 批量导入结果 // Logan.Li
+3 -3
View File
@@ -82,7 +82,7 @@ type SiteTask struct {
// TableName 指定表名
func (SiteTask) TableName() string {
return "site_tasks"
return "ops_site_tasks"
}
// ============================================
@@ -138,7 +138,7 @@ type SiteResult struct {
// TableName 指定表名
func (SiteResult) TableName() string {
return "site_results"
return "ops_site_results"
}
// ============================================
@@ -198,7 +198,7 @@ type SiteAlert struct {
// TableName 指定表名
func (SiteAlert) TableName() string {
return "site_alerts"
return "ops_site_alerts"
}
// SiteTaskCreateRequest 拨测任务创建请求
+5 -5
View File
@@ -92,7 +92,7 @@ type SNMPDevice struct {
// TableName 指定表名
func (SNMPDevice) TableName() string {
return "snmp_devices"
return "ops_snmp_devices"
}
// ============================================
@@ -120,7 +120,7 @@ type SNMPTemplate struct {
// TableName 指定表名
func (SNMPTemplate) TableName() string {
return "snmp_templates"
return "ops_snmp_templates"
}
// SNMPTemplateOID OID模板条目表
@@ -142,7 +142,7 @@ type SNMPTemplateOID struct {
// TableName 指定表名
func (SNMPTemplateOID) TableName() string {
return "snmp_template_oids"
return "ops_snmp_template_oids"
}
// ============================================
@@ -170,7 +170,7 @@ type SNMPMetric struct {
// TableName 指定表名
func (SNMPMetric) TableName() string {
return "snmp_metrics"
return "ops_snmp_metrics"
}
// ============================================
@@ -199,7 +199,7 @@ type SNMPInterface struct {
// TableName 指定表名
func (SNMPInterface) TableName() string {
return "snmp_interfaces"
return "ops_snmp_interfaces"
}
// ============================================
+1 -1
View File
@@ -23,7 +23,7 @@ type TerminalSession struct {
// TableName 表名
func (TerminalSession) TableName() string {
return "terminal_sessions"
return "sys_terminal_sessions"
}
// TerminalSessionQuery 终端会话查询
+4 -8
View File
@@ -3,7 +3,6 @@ package models
import (
"time"
"gorm.io/gorm"
)
// User 用户模型
@@ -21,7 +20,6 @@ type User struct {
LastLogin *time.Time `json:"last_login"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Roles []Role `gorm:"many2many:user_roles;" json:"roles,omitempty"`
@@ -29,7 +27,7 @@ type User struct {
// TableName 表名
func (User) TableName() string {
return "users"
return "iam_users"
}
// Role 角色模型
@@ -41,7 +39,6 @@ type Role struct {
Status int `gorm:"default:1" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
@@ -49,7 +46,7 @@ type Role struct {
// TableName 表名
func (Role) TableName() string {
return "roles"
return "iam_roles"
}
// Permission 权限模型
@@ -65,12 +62,11 @@ type Permission struct {
Status int `gorm:"default:1" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 表名
func (Permission) TableName() string {
return "permissions"
return "iam_permissions"
}
// LoginRequest 登录请求
@@ -143,4 +139,4 @@ type LDAPConfig struct {
UpdatedAt time.Time `json:"updated_at"`
}
func (LDAPConfig) TableName() string { return "ldap_configs" }
func (LDAPConfig) TableName() string { return "iam_ldap_configs" }
+1 -1
View File
@@ -34,7 +34,7 @@ type ZabbixDataSource struct {
// TableName 指定表名
func (ZabbixDataSource) TableName() string {
return "zabbix_datasources"
return "monitor_zabbix_datasources"
}
// ============================================