From 375b6a4bc2afdfa090b1d0dc14ab8d294044b97a Mon Sep 17 00:00:00 2001 From: dushixiang Date: Sun, 14 Dec 2025 22:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=8C=87=E6=A0=87=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app.go | 2 - internal/handler/property_handler.go | 8 -- internal/models/property.go | 18 --- web/src/pages/Settings/MetricsConfig.tsx | 166 ----------------------- web/src/pages/Settings/index.tsx | 11 -- 5 files changed, 205 deletions(-) delete mode 100644 web/src/pages/Settings/MetricsConfig.tsx diff --git a/internal/app.go b/internal/app.go index 00c7fab..f0b5296 100644 --- a/internal/app.go +++ b/internal/app.go @@ -187,8 +187,6 @@ func setupApi(app *orz.App, components *AppComponents) { publicApiWithOptionalAuth.GET("/agents/:id/metrics/latest", components.AgentHandler.GetLatestMetrics) publicApiWithOptionalAuth.GET("/agents/:id/network-interfaces", components.AgentHandler.GetAvailableNetworkInterfaces) publicApiWithOptionalAuth.GET("/agents/:id/traffic", components.AgentHandler.GetTrafficStats) - // 指标配置(公开访问)- 用于获取时间范围选项等配置 - publicApiWithOptionalAuth.GET("/metrics-config", components.PropertyHandler.GetMetricsConfig) // 监控统计数据(公开访问,支持可选认证)- 用于公共展示页面 publicApiWithOptionalAuth.GET("/monitors", components.MonitorHandler.GetMonitors) diff --git a/internal/handler/property_handler.go b/internal/handler/property_handler.go index f9f5980..b9198c5 100644 --- a/internal/handler/property_handler.go +++ b/internal/handler/property_handler.go @@ -7,7 +7,6 @@ import ( "github.com/dushixiang/pika/internal/models" "github.com/dushixiang/pika/internal/service" - "github.com/go-orz/orz" "github.com/labstack/echo/v4" "go.uber.org/zap" ) @@ -151,13 +150,6 @@ func (h *PropertyHandler) GetLogo(c echo.Context) error { return c.Blob(http.StatusOK, contentType, imageData) } -// GetMetricsConfig 获取指标配置(公开访问) -func (h *PropertyHandler) GetMetricsConfig(c echo.Context) error { - return c.JSON(http.StatusOK, orz.Map{ - "options": models.TimeRangeOptions, - }) -} - // TestNotificationChannel 测试通知渠道(从数据库读取配置) func (h *PropertyHandler) TestNotificationChannel(c echo.Context) error { channelType := c.Param("type") diff --git a/internal/models/property.go b/internal/models/property.go index ff14437..2ef57ef 100644 --- a/internal/models/property.go +++ b/internal/models/property.go @@ -62,24 +62,6 @@ type SystemConfig struct { DefaultView string `json:"defaultView"` // 默认视图 grid | list } -// TimeRangeOption 时间范围选项 -type TimeRangeOption struct { - Label string `json:"label"` // 显示标签,如 "15分钟" - Value string `json:"value"` // 值,如 "15m" -} - -var TimeRangeOptions = []TimeRangeOption{ - {Label: "15分钟", Value: "15m"}, - {Label: "30分钟", Value: "30m"}, - {Label: "1小时", Value: "1h"}, - {Label: "3小时", Value: "3h"}, - {Label: "6小时", Value: "6h"}, - {Label: "12小时", Value: "12h"}, - {Label: "1天", Value: "1d"}, - {Label: "3天", Value: "3d"}, - {Label: "7天", Value: "7d"}, -} - // AlertConfig 全局告警配置 type AlertConfig struct { Enabled bool `json:"enabled"` // 是否启用全局告警 diff --git a/web/src/pages/Settings/MetricsConfig.tsx b/web/src/pages/Settings/MetricsConfig.tsx deleted file mode 100644 index a06737e..0000000 --- a/web/src/pages/Settings/MetricsConfig.tsx +++ /dev/null @@ -1,166 +0,0 @@ -import {useEffect} from 'react'; -import {App, Button, Card, Form, InputNumber, Space, Spin} from 'antd'; -import {Database, Clock, BarChart3} from 'lucide-react'; -import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'; -import type {MetricsConfig} from '@/api/property.ts'; -import {getMetricsConfig, saveMetricsConfig} from '@/api/property.ts'; -import {getErrorMessage} from '@/lib/utils'; - -const MetricsConfigComponent = () => { - const [form] = Form.useForm(); - const {message: messageApi} = App.useApp(); - const queryClient = useQueryClient(); - - // 获取指标配置 - const {data: metricsConfig, isLoading} = useQuery({ - queryKey: ['metricsConfig'], - queryFn: getMetricsConfig, - }); - - // 保存指标配置 mutation - const saveMutation = useMutation({ - mutationFn: saveMetricsConfig, - onSuccess: () => { - messageApi.success('配置保存成功'); - queryClient.invalidateQueries({queryKey: ['metricsConfig']}); - }, - onError: (error: unknown) => { - messageApi.error(getErrorMessage(error, '保存配置失败')); - }, - }); - - // 初始化表单 - useEffect(() => { - if (metricsConfig) { - form.setFieldsValue({ - retentionHours: metricsConfig.retentionHours, - maxQueryPoints: metricsConfig.maxQueryPoints, - }); - } - }, [metricsConfig, form]); - - const handleSave = async () => { - try { - const values = await form.validateFields(); - saveMutation.mutate({ - retentionHours: values.retentionHours, - maxQueryPoints: values.maxQueryPoints, - } as MetricsConfig); - } catch (error) { - // 表单验证失败 - } - }; - - const handleReset = () => { - if (metricsConfig) { - form.setFieldsValue({ - retentionHours: metricsConfig.retentionHours, - maxQueryPoints: metricsConfig.maxQueryPoints, - }); - } - }; - - // 计算保留天数 - const getRetentionDays = (hours: number) => { - return (hours / 24).toFixed(1); - }; - - if (isLoading) { - return ( -
- -
- ); - } - - return ( -
-
-

- - 指标数据配置 -

-

配置监控指标数据的保留时长和查询限制,优化存储空间和查询性能

-
- -
- - {/* 数据保留策略 */} - - - 数据保留策略 -
- } - type="inner" - > - - - - - - {({getFieldValue}) => { - const hours = getFieldValue('retentionHours'); - return hours ? ( -
- 当前设置约为 {getRetentionDays(hours)} 天 -
- ) : null; - }} -
- -
-
-
- 💡 保留策略说明 -
-
    -
  • 系统会保留原始数据和多种粒度的聚合数据(1分钟、5分钟、1小时)
  • -
  • 聚合数据自动生成,用于优化长时间范围的查询性能
  • -
  • 较短的保留时长可以节省存储空间,减少数据库压力
  • -
  • 修改后立即生效,下次清理任务时应用新策略(每小时执行一次)
  • -
-
-
- - - {/* 保存按钮 */} - - - - - - - - - - ); -}; - -export default MetricsConfigComponent; diff --git a/web/src/pages/Settings/index.tsx b/web/src/pages/Settings/index.tsx index 815d731..f99a4b2 100644 --- a/web/src/pages/Settings/index.tsx +++ b/web/src/pages/Settings/index.tsx @@ -3,7 +3,6 @@ import {Bell, Database, MessageSquare, Settings2} from 'lucide-react'; import AlertSettings from './AlertSettings'; import NotificationChannels from './NotificationChannels'; import SystemConfig from './SystemConfig'; -import MetricsConfig from './MetricsConfig'; import {PageHeader} from "@/components"; import {useSearchParams} from "react-router-dom"; @@ -22,16 +21,6 @@ const Settings = () => { ), children: , }, - { - key: 'metrics', - label: ( - - - 指标数据配置 - - ), - children: , - }, { key: 'channels', label: (