移除指标配置相关功能

This commit is contained in:
dushixiang committed 2025-12-14 22:54:39 +08:00
1 parent 833b99cea0
commit 375b6a4bc2
5 files changed
-205

No files matched your search

-2
View File
@@ -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)
-8
View File
@@ -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")
-18
View File
@@ -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"` // 是否启用全局告警
-166
View File
@@ -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 (
<div className="flex justify-center items-center py-20">
<Spin />
</div>
);
}
return (
<div>
<div className="mb-6">
<h2 className="text-xl font-bold flex items-center gap-2">
<Database size={20}/>
指标数据配置
</h2>
<p className="text-gray-500 mt-2">配置监控指标数据的保留时长和查询限制,优化存储空间和查询性能</p>
</div>
<Form form={form} layout="vertical" onFinish={handleSave}>
<Space direction="vertical" className="w-full" >
{/* 数据保留策略 */}
<Card
title={
<div className="flex items-center gap-2">
<Clock size={18}/>
<span>数据保留策略</span>
</div>
}
type="inner"
>
<Form.Item
label="数据保留时长"
name="retentionHours"
rules={[
{required: true, message: '请输入数据保留时长'},
{
type: 'number',
min: 24,
max: 720,
message: '保留时长必须在 24-720 小时之间(1-30天)'
},
]}
tooltip="原始指标数据和聚合数据的保留时长,超过此时长的数据将被自动清理"
>
<InputNumber
min={24}
max={720}
step={24}
addonAfter="小时"
style={{width: 200}}
placeholder="168"
/>
</Form.Item>
<Form.Item noStyle shouldUpdate>
{({getFieldValue}) => {
const hours = getFieldValue('retentionHours');
return hours ? (
<div className="mb-4 text-sm text-gray-500">
当前设置约为 <span
className="font-semibold text-blue-600">{getRetentionDays(hours)}</span> 天
</div>
) : null;
}}
</Form.Item>
<div className="p-4 bg-blue-50 dark:bg-blue-950/20 rounded-lg border border-blue-200 dark:border-blue-800">
<div className="text-sm text-blue-800 dark:text-blue-300 space-y-2">
<div className="font-semibold flex items-center gap-2">
💡 保留策略说明
</div>
<ul className="list-disc list-inside space-y-1.5 ml-2">
<li>系统会保留<strong>原始数据</strong>和<strong>多种粒度的聚合数据</strong>(1分钟、5分钟、1小时)</li>
<li>聚合数据自动生成,用于优化长时间范围的查询性能</li>
<li>较短的保留时长可以<strong>节省存储空间</strong>,减少数据库压力</li>
<li>修改后立即生效,下次清理任务时应用新策略(每小时执行一次)</li>
</ul>
</div>
</div>
</Card>
{/* 保存按钮 */}
<Form.Item>
<Space>
<Button type="primary" htmlType="submit" loading={saveMutation.isPending} >
保存配置
</Button>
<Button onClick={handleReset} >
重置
</Button>
</Space>
</Form.Item>
</Space>
</Form>
</div>
);
};
export default MetricsConfigComponent;
-11
View File
@@ -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: <SystemConfig/>,
},
{
key: 'metrics',
label: (
<span className="flex items-center gap-2">
<Database size={16}/>
指标数据配置
</span>
),
children: <MetricsConfig/>,
},
{
key: 'channels',
label: (