feat: AI预测分析接入真实后端数据 + 修复CloudBilling文件损坏
- AIPredictiveAnalytics: 替换3组硬编码mock为实时数据驱动预测 - 指标预测: 基于dashboard metrics时序数据(cpu/memory/disk)线性回归计算斜率与R² - 容量规划: 基于日均增长率推算阈值触及时间(天),动态生成AI扩容建议 - 异常预测: 基于告警规则阈值+当前趋势+事件频率计算异常触发概率 - 概览卡片数据驱动化(置信度基于R²拟合度,高风险/容量预警计数实时计算) - CloudBilling.tsx: 修复read_file导致的行号前缀损坏(501行全部含N|前缀)
This commit is contained in:
1 parent
0ebe22d142
commit
2da4f52209
17 files changed
+2299
-322
No files matched your search
@@ -0,0 +1,108 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CloudBilling 云账单模型 - 每日成本记录
|
||||
type CloudBilling struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"`
|
||||
AccountName string `gorm:"size:128" json:"account_name"`
|
||||
Provider string `gorm:"size:64;index" json:"provider"` // aliyun, tencent, aws, huawei, azure
|
||||
BillingDate string `gorm:"size:10;index;not null" json:"billing_date"` // YYYY-MM-DD
|
||||
Cost float64 `gorm:"type:decimal(12,2);default:0" json:"cost"` // 费用(元)
|
||||
Currency string `gorm:"size:8;default:CNY" json:"currency"` // CNY, USD
|
||||
Service string `gorm:"size:128" json:"service"` // ECS, RDS, OSS, CDN 等
|
||||
Region string `gorm:"size:64" json:"region"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
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"
|
||||
}
|
||||
|
||||
// BillingAlertRule 账单预警规则
|
||||
type BillingAlertRule struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Provider string `gorm:"size:64" json:"provider"` // 空=所有云厂商
|
||||
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"` // 空=所有账号
|
||||
Metric string `gorm:"size:32;default:daily" json:"metric"` // daily, monthly
|
||||
Threshold float64 `gorm:"type:decimal(12,2)" json:"threshold"` // 阈值(元)
|
||||
Operator string `gorm:"size:8;default:>" json:"operator"` // >, >=, <, <=
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
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"
|
||||
}
|
||||
|
||||
// BillingStats 账单统计
|
||||
type BillingStats struct {
|
||||
TodayCost float64 `json:"today_cost"`
|
||||
MonthCost float64 `json:"month_cost"`
|
||||
YearCost float64 `json:"year_cost"`
|
||||
YesterdayCost float64 `json:"yesterday_cost"`
|
||||
MonthTrend []DailyCost `json:"month_trend"`
|
||||
ProviderDist []ProviderCost `json:"provider_dist"`
|
||||
Alerts []BillingAlert `json:"alerts"`
|
||||
}
|
||||
|
||||
// DailyCost 每日成本
|
||||
type DailyCost struct {
|
||||
Date string `json:"date"`
|
||||
Cost float64 `json:"cost"`
|
||||
}
|
||||
|
||||
// ProviderCost 厂商成本分布
|
||||
type ProviderCost struct {
|
||||
Provider string `json:"provider"`
|
||||
Cost float64 `json:"cost"`
|
||||
Percent float64 `json:"percent"`
|
||||
}
|
||||
|
||||
// BillingAlert 账单预警
|
||||
type BillingAlert struct {
|
||||
RuleID uint `json:"rule_id"`
|
||||
RuleName string `json:"rule_name"`
|
||||
Provider string `json:"provider"`
|
||||
Current float64 `json:"current"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Metric string `json:"metric"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
|
||||
// CreateBillingRequest 创建账单记录请求
|
||||
type CreateBillingRequest struct {
|
||||
CloudAccountID *uint `json:"cloud_account_id"`
|
||||
AccountName string `json:"account_name"`
|
||||
Provider string `json:"provider" binding:"required"`
|
||||
BillingDate string `json:"billing_date" binding:"required"`
|
||||
Cost float64 `json:"cost" binding:"required"`
|
||||
Currency string `json:"currency"`
|
||||
Service string `json:"service"`
|
||||
Region string `json:"region"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// CreateBillingAlertRequest 创建预警规则请求
|
||||
type CreateBillingAlertRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Provider string `json:"provider"`
|
||||
CloudAccountID *uint `json:"cloud_account_id"`
|
||||
Metric string `json:"metric"`
|
||||
Threshold float64 `json:"threshold" binding:"required"`
|
||||
Operator string `json:"operator"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
Reference in new issue
Block a user