Files
aiops/backend/internal/models/alert.go
T
attacker 5949ec5d0c 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 工具函数
2026-06-19 01:10:00 +00:00

150 lines
5.5 KiB
Go

package models
import (
"time"
)
// AlertRule 告警规则模型
type AlertRule struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Description string `gorm:"size:500" json:"description"`
Type string `gorm:"size:32;not null" json:"type"` // metric, log, event
Source string `gorm:"size:64;not null" json:"source"` // prometheus, zabbix, custom
Expression string `gorm:"type:text;not null" json:"expression"`
Severity string `gorm:"size:32;default:warning" json:"severity"` // info, warning, critical
Duration int `json:"duration"` // 持续时间(秒)
Enabled bool `gorm:"default:true" json:"enabled"`
Labels string `gorm:"type:text" json:"labels"` // JSON
Annotations string `gorm:"type:text" json:"annotations"` // JSON
NotifyChannels string `gorm:"type:text" json:"notify_channels"` // JSON
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 表名
func (AlertRule) TableName() string {
return "monitor_alert_rules"
}
// AlertEvent 告警事件模型
type AlertEvent struct {
ID uint `gorm:"primarykey" json:"id"`
RuleID uint `json:"rule_id"`
RuleName string `gorm:"size:128" json:"rule_name"`
Severity string `gorm:"size:32" json:"severity"`
Status string `gorm:"size:32;default:firing" json:"status"` // firing, resolved
Target string `gorm:"size:255" json:"target"`
Message string `gorm:"type:text" json:"message"`
Value float64 `json:"value"`
Labels string `gorm:"type:text" json:"labels"`
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at"`
Acknowledged bool `json:"acknowledged"`
AcknowledgedBy *uint `json:"acknowledged_by"`
AcknowledgedAt *time.Time `json:"acknowledged_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联
Rule *AlertRule `json:"rule,omitempty"`
}
// TableName 表名
func (AlertEvent) TableName() string {
return "monitor_alert_events"
}
// NotifyChannel 通知渠道模型
type NotifyChannel struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:64;not null" json:"name"`
Type string `gorm:"size:32;not null" json:"type"` // email, sms, webhook, dingtalk, wechat
Config string `gorm:"type:text" json:"config"` // JSON
Enabled bool `gorm:"default:true" json:"enabled"`
TestStatus string `gorm:"size:32" json:"test_status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 表名
func (NotifyChannel) TableName() string {
return "monitor_notify_channels"
}
// MetricData 监控指标数据
type MetricData struct {
ID uint `gorm:"primarykey" json:"id"`
ServerID *uint `json:"server_id"`
ClusterID *uint `json:"cluster_id"`
Name string `gorm:"size:64" json:"name"`
Value float64 `json:"value"`
Labels string `gorm:"type:text" json:"labels"`
Timestamp time.Time `json:"timestamp"`
}
// TableName 表名
func (MetricData) TableName() string {
return "monitor_metric_data"
}
// CreateAlertRuleRequest 创建告警规则请求
type CreateAlertRuleRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Type string `json:"type" binding:"required,oneof=metric log event"`
Source string `json:"source" binding:"required"`
Expression string `json:"expression" binding:"required"`
Severity string `json:"severity" binding:"omitempty,oneof=info warning critical"`
Duration int `json:"duration"`
Labels string `json:"labels"`
Annotations string `json:"annotations"`
NotifyChannels []string `json:"notify_channels"`
}
// UpdateAlertRuleRequest 更新告警规则请求
type UpdateAlertRuleRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Expression string `json:"expression"`
Severity string `json:"severity" binding:"omitempty,oneof=info warning critical"`
Duration int `json:"duration"`
Enabled *bool `json:"enabled"`
Labels string `json:"labels"`
Annotations string `json:"annotations"`
NotifyChannels []string `json:"notify_channels"`
}
// AlertStats 告警统计
type AlertStats struct {
Total int64 `json:"total"`
Firing int64 `json:"firing"`
Resolved int64 `json:"resolved"`
Critical int64 `json:"critical"`
Warning int64 `json:"warning"`
Info int64 `json:"info"`
TodayCount int64 `json:"today_count"`
WeekCount int64 `json:"week_count"`
}
// AcknowledgeAlertRequest 确认告警请求
type AcknowledgeAlertRequest struct {
Message string `json:"message"`
}
// CreateNotifyChannelRequest 创建通知渠道请求
type CreateNotifyChannelRequest struct {
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required,oneof=email sms webhook dingtalk wechat"`
Config string `json:"config"`
}
// UpdateNotifyChannelRequest 更新通知渠道请求
type UpdateNotifyChannelRequest struct {
Name string `json:"name"`
Type string `json:"type" binding:"omitempty,oneof=email sms webhook dingtalk wechat"`
Config string `json:"config"`
Enabled *bool `json:"enabled"`
}