docs: SYSTEM_MONITOR_API.md contract for the app + drop dead Pm2Logs.tsx
Full /api/system-monitor/* contract (stats snapshot incl. cpu/mem/disks/temp/ gpu/net/power, pm2, docker, and the two SSE log streams) with response shapes, auth (Bearer or ?token=), owner-only note, and the net/power rate caveats — so the app can implement the same views. Also removes the orphaned Pm2Logs.tsx (superseded by LogStream) that a prior commit left tracked. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useClient } from 'hooks/useClient';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
|
||||
const MAX_LINES = 1200;
|
||||
|
||||
// Live pm2 logs for one process (combined out+err), streamed over SSE from /system-monitor/pm2/logs.
|
||||
export const Pm2Logs = ({ id, name, onBack }: { id: number; name: string; onBack: () => void }) => {
|
||||
const { token } = useClient();
|
||||
const [lines, setLines] = useState<string[]>([]);
|
||||
const scrollRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setLines([]);
|
||||
const es = new EventSource(`/api/system-monitor/pm2/logs?id=${id}&lines=150&token=${encodeURIComponent(token ?? '')}`);
|
||||
es.onmessage = (ev) => setLines((prev) => [...prev.slice(-(MAX_LINES - 1)), ev.data]);
|
||||
return () => es.close();
|
||||
}, [id, token]);
|
||||
|
||||
useEffect(() => {
|
||||
scrollRef.current?.scrollTo(0, scrollRef.current.scrollHeight);
|
||||
}, [lines]);
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-full flex-col">
|
||||
<div className="flex shrink-0 items-center gap-2 border-b border-border p-3">
|
||||
<button type="button" onClick={onBack} className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground">
|
||||
<ChevronLeft size={16} /> pm2
|
||||
</button>
|
||||
<span className="font-mono text-sm text-foreground">{name}</span>
|
||||
<span className="ml-auto inline-flex h-2 w-2 animate-pulse rounded-full bg-emerald-500" title="live" />
|
||||
</div>
|
||||
<div ref={scrollRef} className="min-h-0 flex-1 overflow-y-auto bg-black/30 p-3 font-mono text-xs text-foreground/80">
|
||||
{lines.length === 0 ? (
|
||||
<span className="text-muted-foreground">connecting…</span>
|
||||
) : (
|
||||
lines.map((l, i) => <div key={i} className="whitespace-pre-wrap break-words">{l}</div>)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user