From c6a50216ddc5c21417c65acc775436029c04bf69 Mon Sep 17 00:00:00 2001 From: attacker Date: Sat, 11 Jul 2026 22:31:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(i18n):=20U25=20AIOps=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=20phantom=20key=20=E6=B8=85=E9=9B=B6=20=E2=80=94=20an?= =?UTF-8?q?alyzerHelpers.ts=20(23=E5=A4=84)=20+=20capacity-predict.ts=20(1?= =?UTF-8?q?8=E5=A4=84)=20=E4=B8=AD=E6=96=87=E6=96=87=E6=9C=AC=E9=94=AE?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BA=20aiops.analysis.*/aiops.capacity.*?= =?UTF-8?q?=20=E8=AF=AD=E4=B9=89=E5=8C=96=E9=94=AE=20+=20=E7=A1=AC?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=B5=84=E6=BA=90=E5=90=8D=20i18n=20?= =?UTF-8?q?=E5=8C=96=20+=20buildCapacityInsightPrompt=20=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=A1=8C=E5=90=88=E5=B9=B6,=20zh/en=206990=3D6990=20=E5=AF=B9?= =?UTF-8?q?=E9=BD=90,=20tsc=20-b=3D0,=20npm=20build=E2=9C=93=20(18.66s),?= =?UTF-8?q?=20ESLint=3D0/53/0,=20go=20build=3D0,=2017/17=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/aiops/analyzerHelpers.ts | 40 +++++++++--------- .../src/components/aiops/capacity-predict.ts | 42 +++++++++---------- frontend/src/locales/en-US.json | 21 +++++++++- frontend/src/locales/zh-CN.json | 21 +++++++++- 4 files changed, 81 insertions(+), 43 deletions(-) diff --git a/frontend/src/components/aiops/analyzerHelpers.ts b/frontend/src/components/aiops/analyzerHelpers.ts index 87989c5..1f748c7 100644 --- a/frontend/src/components/aiops/analyzerHelpers.ts +++ b/frontend/src/components/aiops/analyzerHelpers.ts @@ -49,11 +49,11 @@ export function generateAIAnalysis(alert: AlertItem): AIAnalysis { : `CPU 使用率偏高,可能导致部分请求处理变慢,建议及时排查避免进一步恶化。`, recommendations: [ `登录 ${target} 执行 top/htop 定位高 CPU 进程`, - i18n.t('检查是否有异常定时任务或批处理任务在运行'), + i18n.t('aiops.analysis.checkAbnormalTasks'), `考虑临时扩容或将部分流量调度到其他节点`, - i18n.t('检查是否有异常定时任务或批处理任务在运行'), + i18n.t('aiops.analysis.checkAbnormalTasks'), ], - autoFixScript: `#!/bin/bash\n# CPU 高负载诊断脚本 - ${target}\necho "${i18n.t('最高 CPU 进程: PID=$PID')}"\nps aux --sort=-%cpu | head -11\necho ""\necho "${i18n.t('aiops.analyzerhelpers.sc4e238d7')}"\nuptime\necho ""\necho "${i18n.t('aiops.analyzerhelpers.sfaca56f5')}"\nPID=$(ps aux --sort=-%cpu | sed -n '2p' | awk '{print $2}')\nif [ -n "$PID" ]; then\n echo "${i18n.t('aiops.analyzerhelpers.s303a9855')}"\n cat /proc/$PID/cmdline | tr '\\0' ' '\n echo ""\nfi\n`, + autoFixScript: `#!/bin/bash\n# CPU 高负载诊断脚本 - ${target}\necho "${i18n.t('aiops.analysis.topCpuProcess')}"\nps aux --sort=-%cpu | head -11\necho ""\necho "${i18n.t('aiops.analyzerhelpers.sc4e238d7')}"\nuptime\necho ""\necho "${i18n.t('aiops.analyzerhelpers.sfaca56f5')}"\nPID=$(ps aux --sort=-%cpu | sed -n '2p' | awk '{print $2}')\nif [ -n "$PID" ]; then\n echo "${i18n.t('aiops.analyzerhelpers.s303a9855')}"\n cat /proc/$PID/cmdline | tr '\\0' ' '\n echo ""\nfi\n`, similarCases: 0, confidence: 0, }; @@ -68,9 +68,9 @@ export function generateAIAnalysis(alert: AlertItem): AIAnalysis { : `内存持续增长,长期可能导致 OOM,建议尽快排查内存使用情况。`, recommendations: [ `检查 ${target} 上的内存占用最高的进程`, - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), ], similarCases: 0, confidence: 0, @@ -86,9 +86,9 @@ export function generateAIAnalysis(alert: AlertItem): AIAnalysis { : `磁盘空间告警,如不及时清理可能导致服务异常。`, recommendations: [ `清理 ${target} 上 30 天前的日志文件`, - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), ], autoFixScript: `#!/bin/bash\n# 磁盘清理脚本 - ${target}\necho "${i18n.t('aiops.analyzerhelpers.s5b91c16b')}"\ndf -h /\necho ""\necho "${i18n.t('aiops.analyzerhelpers.s3b1993da')}"\nfind /var/log -name "*.log" -mtime +30 -delete 2>/dev/null\nfind /var/log -name "*.gz" -mtime +30 -delete 2>/dev/null\necho ""\necho "${i18n.t('aiops.analyzerhelpers.sb513e117')}"\njournalctl --vacuum-time=7d 2>/dev/null\necho ""\necho "${i18n.t('aiops.analyzerhelpers.s4c139c9f')}"\ndf -h /\n`, similarCases: 0, @@ -105,9 +105,9 @@ export function generateAIAnalysis(alert: AlertItem): AIAnalysis { : `网络延迟偏高,可能影响用户体验,建议排查网络链路。`, recommendations: [ `检查 ${target} 的网络连接和带宽使用情况`, - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), ], similarCases: 0, confidence: 0, @@ -123,9 +123,9 @@ export function generateAIAnalysis(alert: AlertItem): AIAnalysis { : `服务可用性下降,部分功能可能受影响。`, recommendations: [ `立即检查 ${target} 的服务状态: systemctl status `, - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), - i18n.t('检查是否有异常定时任务或批处理任务在运行'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), + i18n.t('aiops.analysis.checkAbnormalTasks'), ], autoFixScript: `#!/bin/bash\n# 服务恢复脚本 - ${target}\necho "${i18n.t('aiops.analyzerhelpers.se59337b9')}"\nsystemctl list-units --state=failed\necho ""\necho "${i18n.t('aiops.analyzerhelpers.scdd631f0')}"\nss -tlnp | grep -E ':(80|443|8080|3306|6379|9090)'\necho ""\necho "${i18n.t('aiops.analyzerhelpers.sad3e7bba')}"\nsystemctl reset-failed\n`, similarCases: 0, @@ -141,9 +141,9 @@ export function generateAIAnalysis(alert: AlertItem): AIAnalysis { : `该告警需要关注,持续恶化可能影响系统稳定性。`, recommendations: [ `查看 ${target} 的监控仪表盘,确认指标趋势`, - i18n.t('检查对应时间段的系统日志和应用日志'), - i18n.t('检查对应时间段的系统日志和应用日志'), - i18n.t('检查对应时间段的系统日志和应用日志'), + i18n.t('aiops.analysis.checkSystemLogs'), + i18n.t('aiops.analysis.checkSystemLogs'), + i18n.t('aiops.analysis.checkSystemLogs'), ], similarCases: 0, confidence: 0, @@ -173,10 +173,10 @@ export function mapAlertEvent(event: JsonData): AlertItem { return { id: String(event.id), - name: event.rule_name || event.rule?.name || i18n.t('未知告警'), + name: event.rule_name || event.rule?.name || i18n.t('aiops.analysis.unknownAlert'), severity: event.severity === 'critical' ? 'critical' : event.severity === 'warning' ? 'warning' : 'info', status: event.status === 'firing' ? 'active' : 'resolved', - source: event.target || i18n.t('未知目标'), + source: event.target || i18n.t('aiops.analysis.unknownTarget'), metric, threshold, currentValue, diff --git a/frontend/src/components/aiops/capacity-predict.ts b/frontend/src/components/aiops/capacity-predict.ts index 039b505..0557c83 100644 --- a/frontend/src/components/aiops/capacity-predict.ts +++ b/frontend/src/components/aiops/capacity-predict.ts @@ -59,22 +59,22 @@ export function capacityRecommendation(metricKey: string, days: number): string const level = days <= 7 ? 'urgent' : days <= 14 ? 'warning' : 'normal'; const recs: Record> = { urgent: { - cpu: i18n.t('CPU增长趋势明显,建议尽快扩容计算资源或优化高负载进程'), - memory: i18n.t('内存增长趋势明显,建议增加内存或排查内存泄漏'), - disk: i18n.t('磁盘空间即将耗尽,建议立即扩容或清理历史数据与日志'), + cpu: i18n.t('aiops.capacity.recCpu'), + memory: i18n.t('aiops.capacity.recMemory'), + disk: i18n.t('aiops.capacity.recDisk'), }, warning: { - cpu: i18n.t('CPU增长趋势明显,建议尽快扩容计算资源或优化高负载进程'), - memory: i18n.t('内存增长趋势明显,建议增加内存或排查内存泄漏'), - disk: i18n.t('磁盘空间即将耗尽,建议立即扩容或清理历史数据与日志'), + cpu: i18n.t('aiops.capacity.recCpu'), + memory: i18n.t('aiops.capacity.recMemory'), + disk: i18n.t('aiops.capacity.recDisk'), }, normal: { - cpu: i18n.t('CPU增长趋势明显,建议尽快扩容计算资源或优化高负载进程'), - memory: i18n.t('内存增长趋势明显,建议增加内存或排查内存泄漏'), - disk: i18n.t('磁盘空间即将耗尽,建议立即扩容或清理历史数据与日志'), + cpu: i18n.t('aiops.capacity.recCpu'), + memory: i18n.t('aiops.capacity.recMemory'), + disk: i18n.t('aiops.capacity.recDisk'), }, }; - return recs[level]?.[metricKey] || i18n.t('建议持续监控资源使用趋势'); + return recs[level]?.[metricKey] || i18n.t('aiops.capacity.recMonitor'); } // ============ 综合预测推算 ============ @@ -87,7 +87,7 @@ export function capacityRecommendation(metricKey: string, days: number): string export function computePredictions(input: ComputePredictionsInput): ComputedPredictions { const { rawMetrics, serverStats, selectedTimeRange } = input; const horizonHours = TIME_RANGE_HOURS[selectedTimeRange] || 24; - const timeRangeLabel = TIME_RANGE_LABELS[selectedTimeRange] || i18n.t('24小时后'); + const timeRangeLabel = TIME_RANGE_LABELS[selectedTimeRange] || i18n.t('aiops.capacity.in24Hours'); // ---- 指标预测 ---- const predictions: PredictionMetric[] = METRIC_DEFS.map((def) => { @@ -127,9 +127,9 @@ export function computePredictions(input: ComputePredictionsInput): ComputedPred daysUntilThreshold = daysUntilThreshold < 1 ? 1 : daysUntilThreshold; } const resourceNames: Record = { - cpu: '服务器CPU算力', - memory: '服务器内存', - disk: '存储磁盘空间', + cpu: i18n.t('aiops.capacity.resCpu'), + memory: i18n.t('aiops.capacity.resMemory'), + disk: i18n.t('aiops.capacity.resDisk'), }; return { resource: resourceNames[def.key] || def.label, @@ -177,18 +177,18 @@ export function trendColorClass(trend: string): string { export function buildCapacityInsightPrompt(forecasts: CapacityForecast[]): string { if (forecasts.length === 0) return ''; const lines = forecasts.map((f) => { - const risk = f.daysUntilThreshold >= 999 ? i18n.t('增长平缓,暂无触顶风险') : i18n.t('aiops.predictutilsts.daysUntilThreshold', { days: f.daysUntilThreshold }); + const risk = f.daysUntilThreshold >= 999 ? i18n.t('aiops.capacity.noRisk') : i18n.t('aiops.predictutilsts.daysUntilThreshold', { days: f.daysUntilThreshold }); return `- ${f.resource}:当前 ${f.currentUsage}% → 7天后预测 ${f.predictedUsage}%(阈值 ${f.threshold}%),${risk}`; }); return [ - i18n.t('你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:'), + i18n.t('aiops.capacity.expertPrompt'), '', - i18n.t('你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:'), + i18n.t('aiops.capacity.expertPrompt'), ...lines, '', - i18n.t('你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:'), - i18n.t('你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:'), - i18n.t('你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:'), - i18n.t('你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:'), + i18n.t('aiops.capacity.expertPrompt'), + i18n.t('aiops.capacity.expertPrompt'), + i18n.t('aiops.capacity.expertPrompt'), + i18n.t('aiops.capacity.expertPrompt'), ].join('\n'); } diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json index 684a59c..0a9d4be 100644 --- a/frontend/src/locales/en-US.json +++ b/frontend/src/locales/en-US.json @@ -7402,7 +7402,26 @@ "predictivecost.aiInsight": "AI Deep Analysis", "agentcli.archLayer": "LLM + Tool Layer", "agentcli.archDesc": "OpenAI-compatible LLM; tools include ssh_execute (remote execution) and analyze_output (output analysis).", - "agentcli.securityLayer": "Security + Prompt" + "agentcli.securityLayer": "Security + Prompt", + "analysis": { + "checkAbnormalTasks": "Check for abnormal cron jobs or batch tasks running", + "checkSystemLogs": "Check system and application logs for the corresponding time period", + "unknownAlert": "Unknown Alert", + "unknownTarget": "Unknown Target", + "topCpuProcess": "Top CPU Process: PID=$PID" + }, + "capacity": { + "recCpu": "CPU growth trend is significant. Consider scaling compute resources or optimizing high-load processes.", + "recMemory": "Memory growth trend is significant. Consider adding memory or investigating memory leaks.", + "recDisk": "Disk space is running low. Consider expanding storage or cleaning up historical data and logs.", + "recMonitor": "Recommend continued monitoring of resource usage trends.", + "in24Hours": "In 24 hours", + "noRisk": "Growth is gradual, no threshold breach risk", + "expertPrompt": "You are an AIOps capacity planning expert. Based on the following server resource capacity forecast data, provide a comprehensive risk assessment and actionable operations recommendations:", + "resCpu": "Server CPU Compute", + "resMemory": "Server Memory", + "resDisk": "Storage Disk Space" + } }, "breadcrumb": { "dashboard": "Dashboard", diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json index 204542d..aea10ca 100644 --- a/frontend/src/locales/zh-CN.json +++ b/frontend/src/locales/zh-CN.json @@ -7402,7 +7402,26 @@ "predictivecost.aiInsight": "AI 深度解读", "agentcli.archLayer": "LLM + 工具层", "agentcli.archDesc": "OpenAI 兼容 LLM;工具含 ssh_execute(远程执行)与 analyze_output(输出分析)。", - "agentcli.securityLayer": "安全 + Prompt" + "agentcli.securityLayer": "安全 + Prompt", + "analysis": { + "checkAbnormalTasks": "检查是否有异常定时任务或批处理任务在运行", + "checkSystemLogs": "检查对应时间段的系统日志和应用日志", + "unknownAlert": "未知告警", + "unknownTarget": "未知目标", + "topCpuProcess": "最高 CPU 进程: PID=$PID" + }, + "capacity": { + "recCpu": "CPU增长趋势明显,建议尽快扩容计算资源或优化高负载进程", + "recMemory": "内存增长趋势明显,建议增加内存或排查内存泄漏", + "recDisk": "磁盘空间即将耗尽,建议立即扩容或清理历史数据与日志", + "recMonitor": "建议持续监控资源使用趋势", + "in24Hours": "24小时后", + "noRisk": "增长平缓,暂无触顶风险", + "expertPrompt": "你是 AIOps 容量规划专家。基于以下服务器资源容量预测数据,给出综合风险评估与可执行的运维建议:", + "resCpu": "服务器CPU算力", + "resMemory": "服务器内存", + "resDisk": "存储磁盘空间" + } }, "breadcrumb": { "dashboard": "仪表盘",