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 ( -
配置监控指标数据的保留时长和查询限制,优化存储空间和查询性能
-