|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | +import { Activity, Cpu, CircuitBoard } from 'lucide-react'; |
| 3 | +import { AppProps } from '../../types'; |
| 4 | +import { SystemBridge } from '../../utils/systemBridge'; |
| 5 | + |
| 6 | +const SystemMonitorApp: React.FC<AppProps> = () => { |
| 7 | + const [stats, setStats] = useState<any>(null); |
| 8 | + const [processes, setProcesses] = useState<any[]>([]); |
| 9 | + |
| 10 | + useEffect(() => { |
| 11 | + const fetchStats = async () => { |
| 12 | + const s = await SystemBridge.getSystemStats(); |
| 13 | + const p = await SystemBridge.getProcesses(); |
| 14 | + setStats(s); |
| 15 | + setProcesses(p); |
| 16 | + }; |
| 17 | + fetchStats(); |
| 18 | + const interval = setInterval(fetchStats, 2000); |
| 19 | + return () => clearInterval(interval); |
| 20 | + }, []); |
| 21 | + |
| 22 | + if (!stats) return <div className="p-4 text-white">Connecting to Kernel...</div>; |
| 23 | + |
| 24 | + return ( |
| 25 | + <div className="flex flex-col h-full bg-slate-900 text-slate-100"> |
| 26 | + <div className="p-4 grid grid-cols-4 gap-4 bg-slate-800/50 border-b border-white/5"> |
| 27 | + <div className="bg-slate-800 p-4 rounded-xl border border-white/5 flex items-center gap-4"> |
| 28 | + <div className="p-3 rounded-full bg-blue-500/20 text-blue-400"><Cpu size={24} /></div> |
| 29 | + <div> |
| 30 | + <div className="text-xs text-slate-400">CPU Usage</div> |
| 31 | + <div className="text-xl font-bold">{stats.cpu.toFixed(1)}%</div> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + <div className="bg-slate-800 p-4 rounded-xl border border-white/5 flex items-center gap-4"> |
| 35 | + <div className="p-3 rounded-full bg-purple-500/20 text-purple-400"><CircuitBoard size={24} /></div> |
| 36 | + <div> |
| 37 | + <div className="text-xs text-slate-400">Memory</div> |
| 38 | + <div className="text-xl font-bold">{stats.ram.toFixed(1)}%</div> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + <div className="bg-slate-800 p-4 rounded-xl border border-white/5 flex items-center gap-4"> |
| 42 | + <div className="p-3 rounded-full bg-green-500/20 text-green-400"><Activity size={24} /></div> |
| 43 | + <div> |
| 44 | + <div className="text-xs text-slate-400">Kernel</div> |
| 45 | + <div className="text-sm font-bold truncate max-w-[100px]">{stats.kernel}</div> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + |
| 50 | + <div className="flex-1 overflow-auto"> |
| 51 | + <table className="w-full text-left text-sm"> |
| 52 | + <thead className="bg-slate-800 sticky top-0"> |
| 53 | + <tr> |
| 54 | + <th className="p-3 font-medium text-slate-400">Name</th> |
| 55 | + <th className="p-3 font-medium text-slate-400">PID</th> |
| 56 | + <th className="p-3 font-medium text-slate-400">CPU</th> |
| 57 | + <th className="p-3 font-medium text-slate-400">Mem</th> |
| 58 | + </tr> |
| 59 | + </thead> |
| 60 | + <tbody> |
| 61 | + {processes.map((p) => ( |
| 62 | + <tr key={p.pid} className="border-b border-white/5 hover:bg-white/5"> |
| 63 | + <td className="p-3 font-mono text-blue-300">{p.name}</td> |
| 64 | + <td className="p-3 text-slate-500">{p.pid}</td> |
| 65 | + <td className="p-3">{p.cpu.toFixed(1)}%</td> |
| 66 | + <td className="p-3">{(p.memory / 1024 / 1024).toFixed(1)} MB</td> |
| 67 | + </tr> |
| 68 | + ))} |
| 69 | + </tbody> |
| 70 | + </table> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +export default SystemMonitorApp; |
0 commit comments