修复后端无法编译的问题
This commit is contained in:
1 parent
b9adf96f3a
commit
9de35f5a75
2 files changed
+84
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
// MonitorStats 监控统计数据
|
||||
type MonitorStats struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
AgentID string `gorm:"index:idx_agent_name;uniqueIndex:idx_agent_name_unique" json:"agentId"` // 探针ID
|
||||
MonitorName string `gorm:"index:idx_agent_name;uniqueIndex:idx_agent_name_unique" json:"name"` // 监控项名称
|
||||
MonitorType string `json:"type"` // 监控类型
|
||||
Target string `json:"target"` // 目标地址
|
||||
CurrentResponse int64 `json:"currentResponse"` // 当前响应时间(ms)
|
||||
AvgResponse24h int64 `json:"avgResponse24h"` // 24小时平均响应时间(ms)
|
||||
Uptime24h float64 `json:"uptime24h"` // 24小时在线率(百分比)
|
||||
Uptime30d float64 `json:"uptime30d"` // 30天在线率(百分比)
|
||||
CertExpiryDate int64 `json:"certExpiryDate"` // 证书过期时间(毫秒时间戳),0表示无证书
|
||||
CertExpiryDays int `json:"certExpiryDays"` // 证书剩余天数
|
||||
TotalChecks24h int64 `json:"totalChecks24h"` // 24小时总检测次数
|
||||
SuccessChecks24h int64 `json:"successChecks24h"` // 24小时成功次数
|
||||
TotalChecks30d int64 `json:"totalChecks30d"` // 30天总检测次数
|
||||
SuccessChecks30d int64 `json:"successChecks30d"` // 30天成功次数
|
||||
LastCheckTime int64 `json:"lastCheckTime"` // 最后检测时间
|
||||
LastCheckStatus string `json:"lastCheckStatus"` // 最后检测状态: up/down
|
||||
UpdatedAt int64 `gorm:"autoUpdateTime:milli" json:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
func (MonitorStats) TableName() string {
|
||||
return "monitor_stats"
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/dushixiang/pika/internal/models"
|
||||
"github.com/go-orz/orz"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MonitorStatsRepo struct {
|
||||
orz.Repository[models.MonitorStats, uint]
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewMonitorStatsRepo(db *gorm.DB) *MonitorStatsRepo {
|
||||
return &MonitorStatsRepo{
|
||||
Repository: orz.NewRepository[models.MonitorStats, uint](db),
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// FindByAgentAndName 根据探针ID和监控名称查找统计数据
|
||||
func (r *MonitorStatsRepo) FindByAgentAndName(ctx context.Context, agentID, monitorName string) (*models.MonitorStats, error) {
|
||||
var stats models.MonitorStats
|
||||
err := r.db.WithContext(ctx).
|
||||
Where("agent_id = ? AND monitor_name = ?", agentID, monitorName).
|
||||
First(&stats).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &stats, nil
|
||||
}
|
||||
|
||||
// UpsertStats 插入或更新统计数据
|
||||
func (r *MonitorStatsRepo) UpsertStats(ctx context.Context, stats *models.MonitorStats) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Where("agent_id = ? AND monitor_name = ?", stats.AgentID, stats.MonitorName).
|
||||
Assign(stats).
|
||||
FirstOrCreate(stats).Error
|
||||
}
|
||||
|
||||
// ListByMonitorName 根据监控名称列出所有探针的统计数据
|
||||
func (r *MonitorStatsRepo) ListByMonitorName(ctx context.Context, monitorName string) ([]models.MonitorStats, error) {
|
||||
var statsList []models.MonitorStats
|
||||
err := r.db.WithContext(ctx).
|
||||
Where("monitor_name = ?", monitorName).
|
||||
Find(&statsList).Error
|
||||
return statsList, err
|
||||
}
|
||||
|
||||
// ListAll 列出所有统计数据
|
||||
func (r *MonitorStatsRepo) ListAll(ctx context.Context) ([]models.MonitorStats, error) {
|
||||
var statsList []models.MonitorStats
|
||||
err := r.db.WithContext(ctx).Find(&statsList).Error
|
||||
return statsList, err
|
||||
}
|
||||
Reference in new issue
Block a user