refactor(i18n): U25 AIOps 模块 phantom key 清零 — analyzerHelpers.ts (23处) + capacity-predict.ts (18处) 中文文本键替换为 aiops.analysis.*/aiops.capacity.* 语义化键 + 硬编码资源名 i18n 化 + buildCapacityInsightPrompt 重复行合并, zh/en 6990=6990 对齐, tsc -b=0, npm build✓ (18.66s), ESLint=0/53/0, go build=0, 17/17 测试通过
This commit is contained in:
1 parent
d21eac9117
commit
c6a50216dd
4 files changed
+81
-43
No files matched your search
@@ -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 <service>`,
|
||||
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,
|
||||
|
||||
@@ -59,22 +59,22 @@ export function capacityRecommendation(metricKey: string, days: number): string
|
||||
const level = days <= 7 ? 'urgent' : days <= 14 ? 'warning' : 'normal';
|
||||
const recs: Record<string, Record<string, string>> = {
|
||||
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<string, string> = {
|
||||
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');
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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": "仪表盘",
|
||||
|
||||
Reference in new issue
Block a user