fix: 清理冲突合并产生的行号前缀

This commit is contained in:
attacker committed 2026-06-18 03:37:22 +00:00
1 parent 2354959811
commit 3a0f5ddb52
3 files changed
+529 -532

No files matched your search

+100 -101
View File
@@ -1,101 +1,100 @@
1|# ============================================================ # ============================================================
2|# AIOps Backend + Agent 多阶段 Dockerfile # AIOps Backend + Agent 多阶段 Dockerfile
3|# Stage 1: 编译后端 (Go 1.21) # Stage 1: 编译后端 (Go 1.21)
4|# Stage 2: 交叉编译 Agent (Go 1.24, linux-amd64/arm64 + darwin-arm64) # Stage 2: 交叉编译 Agent (Go 1.24, linux-amd64/arm64 + darwin-arm64)
5|# Stage 3: 运行时 (Alpine) # Stage 3: 运行时 (Alpine)
6|# 署名 Logan.Li # 署名 Logan.Li
7|# ============================================================ # ============================================================
8|
9|# ==================== Stage 1: Backend Builder ==================== # ==================== Stage 1: Backend Builder ====================
10|FROM golang:1.21-alpine AS builder FROM golang:1.21-alpine AS builder
11|
12|WORKDIR /app WORKDIR /app
13|
14|<<<<<<< HEAD <<<<<<< HEAD
15|======= =======
16|# 使用国内 Alpine 镜像源加速 # 使用国内 Alpine 镜像源加速
17|RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
18|
19|# 安装构建依赖 # 安装构建依赖
20|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮) >>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
21|RUN apk add --no-cache git ca-certificates tzdata RUN apk add --no-cache git ca-certificates tzdata
22|
23|ENV TZ=Asia/Shanghai ENV TZ=Asia/Shanghai
24|ENV GOPROXY=https://goproxy.cn,direct ENV GOPROXY=https://goproxy.cn,direct
25|# 跳过 toolchain 校验(GOTOOLCHAIN 自动下载 Go 1.22) # 跳过 toolchain 校验(GOTOOLCHAIN 自动下载 Go 1.22)
26|ENV GONOSUMCHECK=* ENV GONOSUMCHECK=*
27|# 自动下载 Go 1.22 工具链(Redka 需要) # 自动下载 Go 1.22 工具链(Redka 需要)
28|ENV GOTOOLCHAIN=go1.22.2 ENV GOTOOLCHAIN=go1.22.2
29|
30|# 复制后端 go.mod(利用 Docker 层缓存) # 复制后端 go.mod(利用 Docker 层缓存)
31|COPY backend/go.mod backend/go.sum ./ COPY backend/go.mod backend/go.sum ./
32|RUN go mod download RUN go mod download
33|
34|# 复制后端源码 # 复制后端源码
35|COPY backend/ ./ COPY backend/ ./
36|
37|# 构建后端二进制 # 构建后端二进制
38|RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
39| -ldflags="-w -s" \ -ldflags="-w -s" \
40| -o ezops ./cmd/ -o ezops ./cmd/
41|
42|# ==================== Stage 2: Agent Builder ==================== # ==================== Stage 2: Agent Builder ====================
43|FROM golang:1.24-alpine AS agent-builder FROM golang:1.24-alpine AS agent-builder
44|
45|WORKDIR /agent WORKDIR /agent
46|
47|ENV GOPROXY=https://goproxy.cn,direct ENV GOPROXY=https://goproxy.cn,direct
48|ENV GOSUMDB=off ENV GOSUMDB=off
49|
50|# 复制 agent go.mod # 复制 agent go.mod
51|COPY agent/go.mod agent/go.sum ./ COPY agent/go.mod agent/go.sum ./
52|RUN go mod download RUN go mod download
53|
54|# 复制 agent 源码 # 复制 agent 源码
55|COPY agent/ ./ COPY agent/ ./
56|
57|# 交叉编译三个平台的 agent 二进制 # 交叉编译三个平台的 agent 二进制
58|RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-amd64 . && \ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-amd64 . && \
59| CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-arm64 . && \ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-arm64 . && \
60| CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-darwin-arm64 . CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-darwin-arm64 .
61|
62|# ==================== Stage 3: Runtime ==================== # ==================== Stage 3: Runtime ====================
63|FROM alpine:latest FROM alpine:latest
64|
65|<<<<<<< HEAD <<<<<<< HEAD
66|# 安装运行时依赖(curl=健康检查,openssh-client=SSH远程安装agent) # 安装运行时依赖(curl=健康检查,openssh-client=SSH远程安装agent)
67|RUN apk --no-cache add ca-certificates tzdata curl openssh-client RUN apk --no-cache add ca-certificates tzdata curl openssh-client
68|======= =======
69|# 使用国内 Alpine 镜像源加速 # 使用国内 Alpine 镜像源加速
70|RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
71|
72|# 安装运行时依赖 # 安装运行时依赖
73|RUN apk --no-cache add ca-certificates tzdata curl RUN apk --no-cache add ca-certificates tzdata curl
74|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮) >>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
75|
76|ENV TZ=Asia/Shanghai ENV TZ=Asia/Shanghai
77|
78|WORKDIR /app WORKDIR /app
79|
80|# 复制后端二进制 # 复制后端二进制
81|COPY --from=builder /app/ezops . COPY --from=builder /app/ezops .
82|
83|# 创建运行时目录 # 创建运行时目录
84|RUN mkdir -p /app/logs /app/uploads /app/agent/bin /app/agent/deploy RUN mkdir -p /app/logs /app/uploads /app/agent/bin /app/agent/deploy
85|
86|# 复制 agent 二进制(三个平台) # 复制 agent 二进制(三个平台)
87|COPY --from=agent-builder /agent/bin/aiops-agent-linux-amd64 /app/agent/bin/ COPY --from=agent-builder /agent/bin/aiops-agent-linux-amd64 /app/agent/bin/
88|COPY --from=agent-builder /agent/bin/aiops-agent-linux-arm64 /app/agent/bin/ COPY --from=agent-builder /agent/bin/aiops-agent-linux-arm64 /app/agent/bin/
89|COPY --from=agent-builder /agent/bin/aiops-agent-darwin-arm64 /app/agent/bin/ COPY --from=agent-builder /agent/bin/aiops-agent-darwin-arm64 /app/agent/bin/
90|
91|# 复制 agent 安装脚本和 systemd service 模板 # 复制 agent 安装脚本和 systemd service 模板
92|COPY agent/deploy/install.sh /app/agent/deploy/ COPY agent/deploy/install.sh /app/agent/deploy/
93|COPY agent/deploy/aiops-agent.service /app/agent/deploy/ COPY agent/deploy/aiops-agent.service /app/agent/deploy/
94|
95|EXPOSE 8080 EXPOSE 8080
96|
97|HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
98| CMD curl -f http://localhost:8080/health || exit 1 CMD curl -f http://localhost:8080/health || exit 1
99|
100|CMD ["./ezops"] CMD ["./ezops"]
101|
+250 -251
View File
@@ -1,251 +1,250 @@
1|import { useState } from 'react'; import { useState } from 'react';
2|import { toast } from 'sonner'; import { toast } from 'sonner';
3|import { useUserStore } from '@/store'; import { useUserStore } from '@/store';
4|import { import {
5| Dialog, Dialog,
6| DialogContent, DialogContent,
7| DialogDescription, DialogDescription,
8| DialogHeader, DialogHeader,
9| DialogTitle, DialogTitle,
10|} from '@/components/ui/dialog'; } from '@/components/ui/dialog';
11|import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
12|import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
13|import { Copy, Check, Terminal, Download, Settings, Play, Cpu } from 'lucide-react'; import { Copy, Check, Terminal, Download, Settings, Play, Cpu } from 'lucide-react';
14|
15|interface AgentWizardProps { interface AgentWizardProps {
16| open: boolean; open: boolean;
17| onOpenChange: (open: boolean) => void; onOpenChange: (open: boolean) => void;
18|} }
19|
20|/** 自动检测服务器地址:使用当前浏览器访问的地址(协议+主机+端口) */ /** 自动检测服务器地址:使用当前浏览器访问的地址(协议+主机+端口) */
21|function detectServerAddress(): string { function detectServerAddress(): string {
22| if (typeof window !== 'undefined' && window.location) { if (typeof window !== 'undefined' && window.location) {
23| // 直接用当前浏览器的 origin(如 http://10.10.10.150), // 直接用当前浏览器的 origin(如 http://10.10.10.150),
24| // Nginx 会将 /agent/ 请求代理到后端 // Nginx 会将 /agent/ 请求代理到后端
25| return window.location.origin; return window.location.origin;
26| } }
27| return 'http://127.0.0.1:8080'; return 'http://127.0.0.1:8080';
28|} }
29|
30|export function AgentWizard({ open, onOpenChange }: AgentWizardProps) { export function AgentWizard({ open, onOpenChange }: AgentWizardProps) {
31| const token = useUserStore((s) => s.token) || '<YOUR_TOKEN>'; const token = useUserStore((s) => s.token) || '<YOUR_TOKEN>';
32| const serverUrl = detectServerAddress(); const serverUrl = detectServerAddress();
33| const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
34| const [showManualInput, setShowManualInput] = useState(false); const [showManualInput, setShowManualInput] = useState(false);
35|
36| const installCommand = `curl -fsSL ${serverUrl.replace(/^http:/, 'http:')}/agent/install.sh | bash -s -- --server ${serverUrl} --token ${token}`; const installCommand = `curl -fsSL ${serverUrl.replace(/^http:/, 'http:')}/agent/install.sh | bash -s -- --server ${serverUrl} --token ${token}`;
37|
38| const fallbackCopy = (text: string): boolean => { const fallbackCopy = (text: string): boolean => {
39| const textArea = document.createElement('textarea'); const textArea = document.createElement('textarea');
40| textArea.value = text; textArea.value = text;
41| textArea.style.position = 'fixed'; textArea.style.position = 'fixed';
42| textArea.style.left = '-9999px'; textArea.style.left = '-9999px';
43| textArea.style.top = '-9999px'; textArea.style.top = '-9999px';
44| document.body.appendChild(textArea); document.body.appendChild(textArea);
45| textArea.focus(); textArea.focus();
46| textArea.select(); textArea.select();
47| let success = false; let success = false;
48| try { try {
49|<<<<<<< HEAD <<<<<<< HEAD
50| // 优先使用现代 Clipboard API(需要 HTTPS 或 localhost) // 优先使用现代 Clipboard API(需要 HTTPS 或 localhost)
51| if (navigator.clipboard && window.isSecureContext) { if (navigator.clipboard && window.isSecureContext) {
52| await navigator.clipboard.writeText(installCommand); await navigator.clipboard.writeText(installCommand);
53| } else { } else {
54| // 降级方案:用隐藏 textarea + execCommand('copy'),兼容 HTTP 环境 // 降级方案:用隐藏 textarea + execCommand('copy'),兼容 HTTP 环境
55| const textarea = document.createElement('textarea'); const textarea = document.createElement('textarea');
56| textarea.value = installCommand; textarea.value = installCommand;
57| textarea.style.position = 'fixed'; textarea.style.position = 'fixed';
58| textarea.style.opacity = '0'; textarea.style.opacity = '0';
59| textarea.style.pointerEvents = 'none'; textarea.style.pointerEvents = 'none';
60| document.body.appendChild(textarea); document.body.appendChild(textarea);
61| textarea.select(); textarea.select();
62| const ok = document.execCommand('copy'); const ok = document.execCommand('copy');
63| document.body.removeChild(textarea); document.body.removeChild(textarea);
64| if (!ok) throw new Error('execCommand failed'); if (!ok) throw new Error('execCommand failed');
65| } }
66| setCopied(true); setCopied(true);
67| toast.success('安装命令已复制'); toast.success('安装命令已复制');
68| setTimeout(() => setCopied(false), 2000); setTimeout(() => setCopied(false), 2000);
69| } catch { } catch {
70| toast.error('复制失败,请手动选中复制'); toast.error('复制失败,请手动选中复制');
71|======= =======
72| success = document.execCommand('copy'); success = document.execCommand('copy');
73| } catch { } catch {
74| // execCommand also failed // execCommand also failed
75| } }
76| document.body.removeChild(textArea); document.body.removeChild(textArea);
77| return success; return success;
78| }; };
79|
80| const handleCopy = async () => { const handleCopy = async () => {
81| const cmd = installCommand; const cmd = installCommand;
82| let success = false; let success = false;
83|
84| // 方式1: Clipboard API(HTTPS / localhost) // 方式1: Clipboard API(HTTPS / localhost)
85| try { try {
86| await navigator.clipboard.writeText(cmd); await navigator.clipboard.writeText(cmd);
87| success = true; success = true;
88| } catch { } catch {
89| // Clipboard API 不可用 // Clipboard API 不可用
90| } }
91|
92| // 方式2: execCommand fallback(HTTP 也可用) // 方式2: execCommand fallback(HTTP 也可用)
93| if (!success) { if (!success) {
94| success = fallbackCopy(cmd); success = fallbackCopy(cmd);
95| } }
96|
97| if (success) { if (success) {
98| setCopied(true); setCopied(true);
99| toast.success('安装命令已复制到剪贴板,粘贴到目标主机执行'); toast.success('安装命令已复制到剪贴板,粘贴到目标主机执行');
100| setTimeout(() => setCopied(false), 3000); setTimeout(() => setCopied(false), 3000);
101| } else { } else {
102| toast.error('自动复制失败,请在下方代码框中手动全选复制 (Ctrl+A → Ctrl+C)'); toast.error('自动复制失败,请在下方代码框中手动全选复制 (Ctrl+A → Ctrl+C)');
103| // 切换到手选模式,展示可编辑文本框 // 切换到手选模式,展示可编辑文本框
104| setShowManualInput(true); setShowManualInput(true);
105|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮) >>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
106| } }
107| }; };
108|
109| const binaryUrl = `${serverUrl}/agent/aiops-agent-linux-amd64`; const binaryUrl = `${serverUrl}/agent/aiops-agent-linux-amd64`;
110|
111| const manualSteps = [ const manualSteps = [
112| { {
113| icon: Download, icon: Download,
114| title: '1. 下载二进制', title: '1. 下载二进制',
115| commands: [ commands: [
116| `curl -fsSL ${binaryUrl} -o /usr/local/bin/aiops-agent`, `curl -fsSL ${binaryUrl} -o /usr/local/bin/aiops-agent`,
117| ], ],
118| }, },
119| { {
120| icon: Settings, icon: Settings,
121| title: '2. 赋予执行权限', title: '2. 赋予执行权限',
122| commands: ['chmod +x /usr/local/bin/aiops-agent'], commands: ['chmod +x /usr/local/bin/aiops-agent'],
123| }, },
124| { {
125| icon: Cpu, icon: Cpu,
126| title: '3. 创建 systemd 服务', title: '3. 创建 systemd 服务',
127| commands: [ commands: [
128| `cat > /etc/systemd/system/aiops-agent.service << 'EOF'`, `cat > /etc/systemd/system/aiops-agent.service << 'EOF'`,
129| `[Unit]`, `[Unit]`,
130| `Description=AIOps Agent`, `Description=AIOps Agent`,
131| `After=network.target`, `After=network.target`,
132| ``, ``,
133| `[Service]`, `[Service]`,
134| `Type=simple`, `Type=simple`,
135| `ExecStart=/usr/local/bin/aiops-agent --server ${serverUrl} --token ${token}`, `ExecStart=/usr/local/bin/aiops-agent --server ${serverUrl} --token ${token}`,
136| `Restart=always`, `Restart=always`,
137| `RestartSec=5`, `RestartSec=5`,
138| ``, ``,
139| `[Install]`, `[Install]`,
140| `WantedBy=multi-user.target`, `WantedBy=multi-user.target`,
141| `EOF`, `EOF`,
142| ], ],
143| }, },
144| { {
145| icon: Play, icon: Play,
146| title: '4. 启动并设置开机自启', title: '4. 启动并设置开机自启',
147| commands: [ commands: [
148| 'systemctl daemon-reload', 'systemctl daemon-reload',
149| 'systemctl enable --now aiops-agent', 'systemctl enable --now aiops-agent',
150| 'systemctl status aiops-agent', 'systemctl status aiops-agent',
151| ], ],
152| }, },
153| ]; ];
154|
155| return ( return (
156| <Dialog open={open} onOpenChange={onOpenChange}> <Dialog open={open} onOpenChange={onOpenChange}>
157| <DialogContent className="max-w-2xl bg-slate-900 border-slate-800 text-slate-100"> <DialogContent className="max-w-2xl bg-slate-900 border-slate-800 text-slate-100">
158| <DialogHeader> <DialogHeader>
159| <DialogTitle className="text-slate-100">部署 Agent</DialogTitle> <DialogTitle className="text-slate-100">部署 Agent</DialogTitle>
160| <DialogDescription className="text-slate-400"> <DialogDescription className="text-slate-400">
161| 在目标主机上执行以下命令即可完成 Agent 安装与注册 在目标主机上执行以下命令即可完成 Agent 安装与注册
162| </DialogDescription> </DialogDescription>
163| </DialogHeader> </DialogHeader>
164|
165| <Tabs defaultValue="auto" className="w-full"> <Tabs defaultValue="auto" className="w-full">
166| <TabsList className="bg-slate-800 border border-slate-700"> <TabsList className="bg-slate-800 border border-slate-700">
167| <TabsTrigger value="auto" className="data-[state=active]:bg-slate-700"> <TabsTrigger value="auto" className="data-[state=active]:bg-slate-700">
168| <Terminal className="h-4 w-4 mr-1.5" /> <Terminal className="h-4 w-4 mr-1.5" />
169| 安装Agent 安装Agent
170| </TabsTrigger> </TabsTrigger>
171| <TabsTrigger value="manual" className="data-[state=active]:bg-slate-700"> <TabsTrigger value="manual" className="data-[state=active]:bg-slate-700">
172| 手动安装 手动安装
173| </TabsTrigger> </TabsTrigger>
174| </TabsList> </TabsList>
175|
176| {/* 自动安装 */} {/* 自动安装 */}
177| <TabsContent value="auto" className="mt-4 space-y-3"> <TabsContent value="auto" className="mt-4 space-y-3">
178| <p className="text-sm text-slate-400"> <p className="text-sm text-slate-400">
179| 在目标主机执行以下命令,Agent 将自动下载、安装并启动: 在目标主机执行以下命令,Agent 将自动下载、安装并启动:
180| </p> </p>
181| <div className="relative rounded-lg bg-slate-950 border border-slate-800 p-4"> <div className="relative rounded-lg bg-slate-950 border border-slate-800 p-4">
182| <pre className="text-xs text-emerald-400 font-mono whitespace-pre-wrap break-all pr-10"> <pre className="text-xs text-emerald-400 font-mono whitespace-pre-wrap break-all pr-10">
183| {installCommand} {installCommand}
184| </pre> </pre>
185| <Button <Button
186| size="icon" size="icon"
187| variant="ghost" variant="ghost"
188| onClick={handleCopy} onClick={handleCopy}
189| className="absolute top-2 right-2 h-8 w-8 text-slate-400 hover:text-slate-100 hover:bg-slate-800" className="absolute top-2 right-2 h-8 w-8 text-slate-400 hover:text-slate-100 hover:bg-slate-800"
190| title="复制到剪贴板" title="复制到剪贴板"
191| > >
192| {copied ? <Check className="h-4 w-4 text-emerald-400" /> : <Copy className="h-4 w-4" />} {copied ? <Check className="h-4 w-4 text-emerald-400" /> : <Copy className="h-4 w-4" />}
193| </Button> </Button>
194| </div> </div>
195|
196| {/* 手动复制模式:当自动复制失败时展示可全选的文本域 */} {/* 手动复制模式:当自动复制失败时展示可全选的文本域 */}
197| {showManualInput && ( {showManualInput && (
198| <div className="rounded-lg bg-amber-950/30 border border-amber-800/50 p-4"> <div className="rounded-lg bg-amber-950/30 border border-amber-800/50 p-4">
199| <p className="text-xs text-amber-400 mb-2"> <p className="text-xs text-amber-400 mb-2">
200| ⚠️ 自动复制失败。请点击下方输入框全选 (Ctrl+A) 后复制 (Ctrl+C): ⚠️ 自动复制失败。请点击下方输入框全选 (Ctrl+A) 后复制 (Ctrl+C):
201| </p> </p>
202| <textarea <textarea
203| readOnly readOnly
204| value={installCommand} value={installCommand}
205| className="w-full h-24 bg-slate-950 border border-amber-800/30 text-emerald-400 font-mono text-xs p-3 rounded resize-none focus:outline-none focus:border-amber-600" className="w-full h-24 bg-slate-950 border border-amber-800/30 text-emerald-400 font-mono text-xs p-3 rounded resize-none focus:outline-none focus:border-amber-600"
206| onClick={(e) => (e.target as HTMLTextAreaElement).select()} onClick={(e) => (e.target as HTMLTextAreaElement).select()}
207| /> />
208| </div> </div>
209| )} )}
210| <div className="flex items-start gap-2 text-xs text-slate-500"> <div className="flex items-start gap-2 text-xs text-slate-500">
211| <Terminal className="h-3.5 w-3.5 mt-0.5 shrink-0" /> <Terminal className="h-3.5 w-3.5 mt-0.5 shrink-0" />
212| <span> <span>
213| 服务器地址已自动检测为当前访问地址({serverUrl})。Agent 安装成功后将自动连接并开始上报指标。 服务器地址已自动检测为当前访问地址({serverUrl})。Agent 安装成功后将自动连接并开始上报指标。
214| </span> </span>
215| </div> </div>
216| </TabsContent> </TabsContent>
217|
218| {/* 手动安装 */} {/* 手动安装 */}
219| <TabsContent value="manual" className="mt-4 space-y-4"> <TabsContent value="manual" className="mt-4 space-y-4">
220| <div className="max-h-[420px] overflow-y-auto space-y-3 pr-1"> <div className="max-h-[420px] overflow-y-auto space-y-3 pr-1">
221| {manualSteps.map((step) => ( {manualSteps.map((step) => (
222| <div key={step.title} className="rounded-lg bg-slate-950 border border-slate-800 overflow-hidden"> <div key={step.title} className="rounded-lg bg-slate-950 border border-slate-800 overflow-hidden">
223| <div className="flex items-center gap-2 px-4 py-2.5 bg-slate-800/50"> <div className="flex items-center gap-2 px-4 py-2.5 bg-slate-800/50">
224| <step.icon className="h-4 w-4 text-blue-400" /> <step.icon className="h-4 w-4 text-blue-400" />
225| <span className="text-sm font-medium text-slate-200">{step.title}</span> <span className="text-sm font-medium text-slate-200">{step.title}</span>
226| </div> </div>
227| <div className="p-3 space-y-1"> <div className="p-3 space-y-1">
228| {step.commands.map((cmd, idx) => ( {step.commands.map((cmd, idx) => (
229| <div key={idx} className="flex items-start gap-2"> <div key={idx} className="flex items-start gap-2">
230| <span className="text-slate-600 font-mono text-xs select-none mt-0.5">$</span> <span className="text-slate-600 font-mono text-xs select-none mt-0.5">$</span>
231| <code className="text-xs text-slate-300 font-mono whitespace-pre-wrap break-all flex-1"> <code className="text-xs text-slate-300 font-mono whitespace-pre-wrap break-all flex-1">
232| {cmd} {cmd}
233| </code> </code>
234| </div> </div>
235| ))} ))}
236| </div> </div>
237| </div> </div>
238| ))} ))}
239| </div> </div>
240| <p className="text-xs text-slate-500"> <p className="text-xs text-slate-500">
241| 完成上述步骤后,Agent 将作为 systemd 服务运行并自动上报指标。 完成上述步骤后,Agent 将作为 systemd 服务运行并自动上报指标。
242| </p> </p>
243| </TabsContent> </TabsContent>
244| </Tabs> </Tabs>
245| </DialogContent> </DialogContent>
246| </Dialog> </Dialog>
247| ); );
248|} }
249|
250|export default AgentWizard; export default AgentWizard;
251|
+179 -180
View File
@@ -1,180 +1,179 @@
1|// 服务器表格行 — 纯展示子组件(接收 props,不直接调 API) // Logan.Li // 服务器表格行 — 纯展示子组件(接收 props,不直接调 API) // Logan.Li
2|import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
3|import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';
4|import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
5|import { Checkbox } from '@/components/ui/checkbox'; import { Checkbox } from '@/components/ui/checkbox';
6|import { import {
7| DropdownMenu, DropdownMenu,
8| DropdownMenuContent, DropdownMenuContent,
9| DropdownMenuItem, DropdownMenuItem,
10| DropdownMenuLabel, DropdownMenuLabel,
11| DropdownMenuSeparator, DropdownMenuSeparator,
12| DropdownMenuTrigger, DropdownMenuTrigger,
13|} from '@/components/ui/dropdown-menu'; } from '@/components/ui/dropdown-menu';
14|import { TableCell, TableRow } from '@/components/ui/table'; import { TableCell, TableRow } from '@/components/ui/table';
15|<<<<<<< HEAD <<<<<<< HEAD
16|import { Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2, Download } from 'lucide-react'; import { Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2, Download } from 'lucide-react';
17|======= =======
18|import { Cpu, Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2 } from 'lucide-react'; import { Cpu, Edit, MoreHorizontal, Server as ServerIcon, Terminal, Trash2 } from 'lucide-react';
19|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮) >>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
20|import { getStatusBadge, getTags, getUsageColor } from './serverHelpers'; import { getStatusBadge, getTags, getUsageColor } from './serverHelpers';
21|
22|interface ServerTableRowProps { interface ServerTableRowProps {
23| server: any; server: any;
24| selected: boolean; selected: boolean;
25| onToggleSelect: (id: string) => void; onToggleSelect: (id: string) => void;
26| onOpenTerminal: (server: any) => void; onOpenTerminal: (server: any) => void;
27| onOpenEdit: (server: any) => void; onOpenEdit: (server: any) => void;
28| onDelete: (id: string) => void; onDelete: (id: string) => void;
29| onInstallAgent: (server: any) => void; onInstallAgent: (server: any) => void;
30|} }
31|
32|export function ServerTableRow({ export function ServerTableRow({
33| server, server,
34| selected, selected,
35| onToggleSelect, onToggleSelect,
36| onOpenTerminal, onOpenTerminal,
37| onOpenEdit, onOpenEdit,
38| onDelete, onDelete,
39| onInstallAgent, onInstallAgent,
40|}: ServerTableRowProps) { }: ServerTableRowProps) {
41| const cpuUsage = Number(server.cpu_usage || 0); const cpuUsage = Number(server.cpu_usage || 0);
42| const memoryUsage = Number(server.memory_usage || 0); const memoryUsage = Number(server.memory_usage || 0);
43| const tags = getTags(server); const tags = getTags(server);
44| const memGB = server.memory ? Math.round(server.memory / 1024) : 0; const memGB = server.memory ? Math.round(server.memory / 1024) : 0;
45|
46| return ( return (
47| <TableRow className="border-[var(--dg-border)] hover:bg-[var(--dg-bg-tertiary)]/50"> <TableRow className="border-[var(--dg-border)] hover:bg-[var(--dg-bg-tertiary)]/50">
48| <TableCell> <TableCell>
49| <Checkbox <Checkbox
50| checked={selected} checked={selected}
51| onCheckedChange={() => onToggleSelect(server.id)} onCheckedChange={() => onToggleSelect(server.id)}
52| className="border-[var(--dg-border)]" className="border-[var(--dg-border)]"
53| /> />
54| </TableCell> </TableCell>
55| <TableCell> <TableCell>
56| <div className="flex items-center gap-2"> <div className="flex items-center gap-2">
57| <ServerIcon className="h-4 w-4 text-[var(--dg-text-muted)]" /> <ServerIcon className="h-4 w-4 text-[var(--dg-text-muted)]" />
58| <div> <div>
59| <p className="font-medium text-[var(--dg-text-primary)]">{server.hostname}</p> <p className="font-medium text-[var(--dg-text-primary)]">{server.hostname}</p>
60| <p className="text-xs text-[var(--dg-text-muted)]">{server.os}</p> <p className="text-xs text-[var(--dg-text-muted)]">{server.os}</p>
61| </div> </div>
62| </div> </div>
63| </TableCell> </TableCell>
64| <TableCell> <TableCell>
65| <code className="text-sm text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)] px-2 py-0.5 rounded"> <code className="text-sm text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)] px-2 py-0.5 rounded">
66| {server.ip} {server.ip}
67| </code> </code>
68| </TableCell> </TableCell>
69| <TableCell> <TableCell>
70| {server.public_ip ? ( {server.public_ip ? (
71| <code className="text-sm text-[var(--dg-cyan)] bg-[var(--dg-cyan)]/10 px-2 py-0.5 rounded"> <code className="text-sm text-[var(--dg-cyan)] bg-[var(--dg-cyan)]/10 px-2 py-0.5 rounded">
72| {server.public_ip} {server.public_ip}
73| </code> </code>
74| ) : ( ) : (
75| <span className="text-sm text-[var(--dg-text-muted)]">-</span> <span className="text-sm text-[var(--dg-text-muted)]">-</span>
76| )} )}
77| </TableCell> </TableCell>
78| <TableCell>{getStatusBadge(server.status)}</TableCell> <TableCell>{getStatusBadge(server.status)}</TableCell>
79| <TableCell> <TableCell>
80| <div className="text-sm text-[var(--dg-text-secondary)]"> <div className="text-sm text-[var(--dg-text-secondary)]">
81| <span className="text-[var(--dg-text-muted)]">{server.cpu}核</span> <span className="text-[var(--dg-text-muted)]">{server.cpu}核</span>
82| <span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span> <span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span>
83| <span className="text-[var(--dg-text-muted)]">{memGB}GB</span> <span className="text-[var(--dg-text-muted)]">{memGB}GB</span>
84| <span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span> <span className="mx-1 text-[var(--dg-text-muted)] opacity-50">/</span>
85| <span className="text-[var(--dg-text-muted)]">{server.disk}GB</span> <span className="text-[var(--dg-text-muted)]">{server.disk}GB</span>
86| </div> </div>
87| </TableCell> </TableCell>
88| <TableCell> <TableCell>
89| <div className="space-y-1"> <div className="space-y-1">
90| <div className="flex items-center gap-2"> <div className="flex items-center gap-2">
91| <span className="text-xs text-[var(--dg-text-muted)] w-8">CPU</span> <span className="text-xs text-[var(--dg-text-muted)] w-8">CPU</span>
92| <div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden"> <div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden">
93| <div <div
94| className={cn('h-full rounded-full', getUsageColor(cpuUsage))} className={cn('h-full rounded-full', getUsageColor(cpuUsage))}
95| style={{ width: `${cpuUsage}%` }} style={{ width: `${cpuUsage}%` }}
96| /> />
97| </div> </div>
98| <span className="text-xs text-[var(--dg-text-secondary)]">{cpuUsage.toFixed(1)}%</span> <span className="text-xs text-[var(--dg-text-secondary)]">{cpuUsage.toFixed(1)}%</span>
99| </div> </div>
100| <div className="flex items-center gap-2"> <div className="flex items-center gap-2">
101| <span className="text-xs text-[var(--dg-text-muted)] w-8">内存</span> <span className="text-xs text-[var(--dg-text-muted)] w-8">内存</span>
102| <div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden"> <div className="w-16 h-1.5 bg-[var(--dg-bg-tertiary)] rounded-full overflow-hidden">
103| <div <div
104| className={cn('h-full rounded-full', getUsageColor(memoryUsage))} className={cn('h-full rounded-full', getUsageColor(memoryUsage))}
105| style={{ width: `${memoryUsage}%` }} style={{ width: `${memoryUsage}%` }}
106| /> />
107| </div> </div>
108| <span className="text-xs text-[var(--dg-text-secondary)]">{memoryUsage.toFixed(1)}%</span> <span className="text-xs text-[var(--dg-text-secondary)]">{memoryUsage.toFixed(1)}%</span>
109| </div> </div>
110| </div> </div>
111| </TableCell> </TableCell>
112| <TableCell> <TableCell>
113| <div className="flex flex-wrap gap-1"> <div className="flex flex-wrap gap-1">
114| {tags.slice(0, 3).map((tag) => ( {tags.slice(0, 3).map((tag) => (
115| <Badge <Badge
116| key={tag} key={tag}
117| variant="outline" variant="outline"
118| className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)]/50" className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)] bg-[var(--dg-bg-tertiary)]/50"
119| > >
120| {tag} {tag}
121| </Badge> </Badge>
122| ))} ))}
123| {tags.length > 3 && ( {tags.length > 3 && (
124| <Badge variant="outline" className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)]"> <Badge variant="outline" className="text-xs border-[var(--dg-border)] text-[var(--dg-text-secondary)]">
125| +{tags.length - 3} +{tags.length - 3}
126| </Badge> </Badge>
127| )} )}
128| </div> </div>
129| </TableCell> </TableCell>
130| <TableCell className="text-right"> <TableCell className="text-right">
131| <div className="flex items-center justify-end gap-1"> <div className="flex items-center justify-end gap-1">
132| <Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-blue)]" onClick={() => onOpenTerminal(server)}> <Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-blue)]" onClick={() => onOpenTerminal(server)}>
133| <Terminal className="h-4 w-4" /> <Terminal className="h-4 w-4" />
134| </Button> </Button>
135| <DropdownMenu> <DropdownMenu>
136| <DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
137| <Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)]"> <Button variant="ghost" size="icon" className="h-8 w-8 text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)]">
138| <MoreHorizontal className="h-4 w-4" /> <MoreHorizontal className="h-4 w-4" />
139| </Button> </Button>
140| </DropdownMenuTrigger> </DropdownMenuTrigger>
141| <DropdownMenuContent align="end" className="w-48 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)]"> <DropdownMenuContent align="end" className="w-48 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)]">
142| <DropdownMenuLabel className="text-[var(--dg-text-secondary)]">操作</DropdownMenuLabel> <DropdownMenuLabel className="text-[var(--dg-text-secondary)]">操作</DropdownMenuLabel>
143| <DropdownMenuSeparator className="bg-[var(--dg-border)]" /> <DropdownMenuSeparator className="bg-[var(--dg-border)]" />
144| <DropdownMenuItem <DropdownMenuItem
145| className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer" className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
146| onClick={() => onOpenEdit(server)} onClick={() => onOpenEdit(server)}
147| > >
148| <Edit className="h-4 w-4 mr-2" /> <Edit className="h-4 w-4 mr-2" />
149| 编辑 编辑
150| </DropdownMenuItem> </DropdownMenuItem>
151| <DropdownMenuItem <DropdownMenuItem
152| className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer" className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
153| onClick={() => onOpenTerminal(server)} onClick={() => onOpenTerminal(server)}
154| > >
155| <Terminal className="h-4 w-4 mr-2" /> <Terminal className="h-4 w-4 mr-2" />
156| 终端 终端
157| </DropdownMenuItem> </DropdownMenuItem>
158| <DropdownMenuItem <DropdownMenuItem
159| className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer" className="text-[var(--dg-text-secondary)] focus:bg-[var(--dg-bg-hover)] focus:text-[var(--dg-text-primary)] cursor-pointer"
160| onClick={() => onInstallAgent(server)} onClick={() => onInstallAgent(server)}
161| > >
162| <Cpu className="h-4 w-4 mr-2" /> <Cpu className="h-4 w-4 mr-2" />
163| 安装Agent 安装Agent
164| </DropdownMenuItem> </DropdownMenuItem>
165| <DropdownMenuSeparator className="bg-[var(--dg-border)]" /> <DropdownMenuSeparator className="bg-[var(--dg-border)]" />
166| <DropdownMenuItem <DropdownMenuItem
167| className="text-red-400 focus:bg-[var(--dg-bg-hover)] focus:text-red-400 cursor-pointer" className="text-red-400 focus:bg-[var(--dg-bg-hover)] focus:text-red-400 cursor-pointer"
168| onClick={() => onDelete(server.id)} onClick={() => onDelete(server.id)}
169| > >
170| <Trash2 className="h-4 w-4 mr-2" /> <Trash2 className="h-4 w-4 mr-2" />
171| 删除 删除
172| </DropdownMenuItem> </DropdownMenuItem>
173| </DropdownMenuContent> </DropdownMenuContent>
174| </DropdownMenu> </DropdownMenu>
175| </div> </div>
176| </TableCell> </TableCell>
177| </TableRow> </TableRow>
178| ); );
179|} }
180|