diff --git a/internal/scheduler/monitor_scheduler.go b/internal/scheduler/monitor_scheduler.go index 116800e..8fbee3b 100644 --- a/internal/scheduler/monitor_scheduler.go +++ b/internal/scheduler/monitor_scheduler.go @@ -189,10 +189,8 @@ func (s *MonitorScheduler) executeTask(task *MonitorTask) { // reloadTasks 重新加载任务列表 func (s *MonitorScheduler) reloadTasks() { // 获取所有启用的监控任务 - var monitors []models.MonitorTask - if err := s.monitorService.MonitorRepo.GetDB(s.ctx). - Where("enabled = ?", true). - Find(&monitors).Error; err != nil { + monitors, err := s.monitorService.FindByEnabled(context.Background(), true) + if err != nil { s.logger.Error("加载监控任务失败", zap.Error(err)) return } diff --git a/internal/service/monitor_service.go b/internal/service/monitor_service.go index 01dfbd8..4937392 100644 --- a/internal/service/monitor_service.go +++ b/internal/service/monitor_service.go @@ -32,11 +32,13 @@ type MonitorService struct { func NewMonitorService(logger *zap.Logger, db *gorm.DB, wsManager *ws.Manager) *MonitorService { return &MonitorService{ logger: logger, + Service: orz.NewService(db), MonitorRepo: repo.NewMonitorRepo(db), agentRepo: repo.NewAgentRepo(db), metricRepo: repo.NewMetricRepo(db), monitorStatsRepo: repo.NewMonitorStatsRepo(db), - wsManager: wsManager, + + wsManager: wsManager, } } diff --git a/web/src/pages/Monitors/MonitorList.tsx b/web/src/pages/Monitors/MonitorList.tsx index 60091ad..5737dbc 100644 --- a/web/src/pages/Monitors/MonitorList.tsx +++ b/web/src/pages/Monitors/MonitorList.tsx @@ -13,7 +13,7 @@ import {getErrorMessage} from '../../lib/utils'; const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']; const MonitorList = () => { - const {message} = App.useApp(); + const {message, modal} = App.useApp(); const actionRef = useRef(null); const [form] = Form.useForm(); @@ -122,10 +122,9 @@ const MonitorList = () => { }; const handleDelete = async (monitor: MonitorTask) => { - Modal.confirm({ + modal.confirm({ title: '删除监控项', content: `确定要删除监控「${monitor.name}」吗?`, - centered: true, okButtonProps: {danger: true}, onOk: async () => { try { diff --git a/web/src/pages/Public/MonitorDetail.tsx b/web/src/pages/Public/MonitorDetail.tsx index 70ef605..7ab0704 100644 --- a/web/src/pages/Public/MonitorDetail.tsx +++ b/web/src/pages/Public/MonitorDetail.tsx @@ -14,17 +14,8 @@ import { TrendingUp } from 'lucide-react'; import type {TooltipProps} from 'recharts'; -import { - Area, - AreaChart, - CartesianGrid, - Legend, - ResponsiveContainer, - Tooltip, - XAxis, - YAxis, -} from 'recharts'; -import {getMonitorStatsById, getMonitorHistory, type AggregatedMonitorMetric} from '../../api/monitor'; +import {Area, AreaChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis,} from 'recharts'; +import {type AggregatedMonitorMetric, getMonitorHistory, getMonitorStatsById} from '../../api/monitor'; import type {MonitorStats} from '../../types'; const formatTime = (ms: number): string => { @@ -70,7 +61,8 @@ const LoadingSpinner = () => ( const EmptyState = ({message = '监控数据不存在'}: { message?: string }) => (
-
+

{message}

@@ -111,13 +103,16 @@ const Card = ({ action?: ReactNode; children: ReactNode; }) => ( -
+
{(title || description || action) && (
- {title ?

{title}

: null} - {description ?

{description}

: null} + {title ? +

{title}

: null} + {description ? +

{description}

: null}
{action ?
{action}
: null}
@@ -142,7 +137,8 @@ const StatusBadge = ({status}: { status: string }) => { } return ( -
+
{icon} {label}
@@ -196,7 +192,8 @@ const StatCard = ({icon, label, value, color = 'blue'}: { const theme = statThemes[color as keyof typeof statThemes] ?? statThemes.blue; return ( -
+
@@ -215,13 +212,18 @@ const StatCard = ({icon, label, value, color = 'blue'}: { ); }; -const CustomTooltip = ({active, payload, label, unit = ' ms'}: TooltipProps & { unit?: string; label?: string; payload?: any[] }) => { +const CustomTooltip = ({active, payload, label, unit = ' ms'}: TooltipProps & { + unit?: string; + label?: string; + payload?: any[] +}) => { if (!active || !payload || payload.length === 0) { return null; } return ( -
+

{label}

{payload.map((entry, index) => { @@ -239,7 +241,8 @@ const CustomTooltip = ({active, payload, label, unit = ' ms'}: TooltipProps +

{

{/* Hero Section */} -
-
+
+
@@ -422,7 +427,8 @@ const MonitorDetail = () => { 返回监控列表
-
+
{firstStat.type === 'tcp' ? ( ) : ( @@ -529,7 +535,8 @@ const MonitorDetail = () => { }`}> 证书到期时间: {formatDate(firstStat.certExpiryDate)} {certExpired ? ( - (已过期 {Math.abs(firstStat.certExpiryDays)} 天) + (已过期 {Math.abs(firstStat.certExpiryDays)} 天) ) : ( (剩余 {firstStat.certExpiryDays} 天) )} @@ -556,7 +563,8 @@ const MonitorDetail = () => { description="监控各探针的响应时间变化" action={
- + {availableAgents.length > 0 && (