'use client'; import React, { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Loader2, Database, AlertTriangle, Trash2, Eye, Zap, Skull } from 'lucide-react'; interface ConnectionStatus { currentConnections: number; maxConnections: number; usagePercentage: number; connectionDetails: Array<{ ID: number; USER: string; HOST: string; DB: string; COMMAND: string; TIME: number; STATE: string; INFO?: string; }>; connectionCount: number; } export default function UltimateKillPage() { const [status, setStatus] = useState(null); const [loading, setLoading] = useState(false); const [message, setMessage] = useState(''); const [error, setError] = useState(''); // 獲取連線狀態 const fetchStatus = async () => { try { setLoading(true); const response = await fetch('/api/ultimate-kill?action=status'); const data = await response.json(); if (data.success) { setStatus(data.data); setMessage('狀態更新成功'); setError(''); } else { setError(data.error || '獲取狀態失敗'); } } catch (err) { setError('網路錯誤: ' + (err instanceof Error ? err.message : '未知錯誤')); } finally { setLoading(false); } }; // 終極清理 - 殺死所有連線 const ultimateKill = async () => { if (!confirm('確定要執行終極清理嗎?這會強制殺死所有資料庫連線!')) { return; } try { setLoading(true); const response = await fetch('/api/ultimate-kill', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ action: 'kill-all' }), }); const data = await response.json(); if (data.success) { setMessage(data.message || '終極清理完成'); setError(''); await fetchStatus(); // 重新獲取狀態 } else { setError(data.error || '終極清理失敗'); } } catch (err) { setError('終極清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤')); } finally { setLoading(false); } }; // 強制重啟資料庫連線 const forceRestart = async () => { if (!confirm('確定要強制重啟資料庫連線嗎?這會先殺死所有連線然後重新建立!')) { return; } try { setLoading(true); const response = await fetch('/api/ultimate-kill', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ action: 'restart' }), }); const data = await response.json(); if (data.success) { setMessage(data.message || '強制重啟完成'); setError(''); await fetchStatus(); // 重新獲取狀態 } else { setError(data.error || '強制重啟失敗'); } } catch (err) { setError('強制重啟錯誤: ' + (err instanceof Error ? err.message : '未知錯誤')); } finally { setLoading(false); } }; // 組件載入時獲取狀態 useEffect(() => { fetchStatus(); // 每10秒自動更新狀態 const interval = setInterval(fetchStatus, 10000); return () => clearInterval(interval); }, []); return (

終極連線清理

強制殺死所有資料庫連線 - 最後手段

{/* 嚴重警告 */} 嚴重警告: 這些操作會立即強制殺死所有資料庫連線,可能導致正在運行的應用程式崩潰。請確保沒有重要操作正在進行! {/* 連線狀態概覽 */} {status && (

總連線數

{status.currentConnections}

最大連線數

{status.maxConnections}

使用率

{status.usagePercentage.toFixed(1)}%

狀態

{status.connectionCount <= 1 ? '正常' : '異常'}

)} {/* 終極操作 */} 終極操作 強制殺死所有資料庫連線 - 最後手段
{/* 連線詳情列表 */} {status && status.connectionDetails.length > 0 && ( 連線詳情列表 當前所有資料庫連線的詳細信息
{status.connectionDetails.map((conn, index) => (
#{conn.ID}

用戶: {conn.USER} | 主機: {conn.HOST}

資料庫: {conn.DB} | 命令: {conn.COMMAND}

時間: {conn.TIME}s | 狀態: {conn.STATE}

{conn.INFO && (

查詢: {conn.INFO.length > 100 ? conn.INFO.substring(0, 100) + '...' : conn.INFO}

)}
))}
)} {/* 訊息顯示 */} {message && ( {message} )} {error && ( {error} )} {/* 使用說明 */} 終極清理說明

終極清理: 直接殺死資料庫中的所有連線,立即生效

強制重啟: 先殺死所有連線,等待系統穩定,然後重新建立連線

自動更新: 頁面每10秒自動更新連線狀態

最後手段: 這些操作是最後的手段,會立即終止所有連線

• 建議先嘗試「終極清理」,如果問題持續再使用「強制重啟」

); }