diff --git a/ui/src/api/client.ts b/ui/src/api/client.ts index 46ba4097c..2af443c05 100644 --- a/ui/src/api/client.ts +++ b/ui/src/api/client.ts @@ -173,6 +173,14 @@ export const api = { }, clearLog: (type?: string) => apiFetch<{ success: boolean }>(`/log?type=${type ?? 'ops'}`, { method: 'DELETE' }), + getLogStats: (type?: string, filters?: { cmd?: string; status?: string; since?: string }) => { + const params = new URLSearchParams(); + params.set('type', type ?? 'ops'); + if (filters?.cmd) params.set('cmd', filters.cmd); + if (filters?.status) params.set('status', filters.status); + if (filters?.since) params.set('since', filters.since); + return apiFetch(`/log/stats?${params.toString()}`); + }, // Audit auditAll: () => apiFetch('/audit'), @@ -466,6 +474,21 @@ export interface LogListResponse { commands: string[]; } +export interface CommandStats { + total: number; + ok: number; + error: number; + partial: number; + blocked: number; +} + +export interface LogStatsResponse { + total: number; + success_rate: number; + by_command: Record; + last_operation?: LogEntry; +} + // Audit types export interface AuditFinding { severity: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | 'INFO'; diff --git a/ui/src/lib/queryKeys.ts b/ui/src/lib/queryKeys.ts index 5467b2d9f..af7dd1866 100644 --- a/ui/src/lib/queryKeys.ts +++ b/ui/src/lib/queryKeys.ts @@ -26,6 +26,8 @@ export const queryKeys = { log: (type: string, limit: number, filters?: Record) => ['log', type, limit, filters ?? {}] as const, + logStats: (type: string, filters?: Record) => + ['log-stats', type, filters ?? {}] as const, config: ['config'] as const, }; diff --git a/ui/src/pages/LogPage.tsx b/ui/src/pages/LogPage.tsx index c5f25acf9..636632898 100644 --- a/ui/src/pages/LogPage.tsx +++ b/ui/src/pages/LogPage.tsx @@ -2,7 +2,7 @@ import { useState, useEffect, useMemo } from 'react'; import { ScrollText, Trash2, RefreshCw, ChevronLeft, ChevronRight } from 'lucide-react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { api } from '../api/client'; -import type { LogEntry } from '../api/client'; +import type { LogEntry, LogStatsResponse } from '../api/client'; import { queryKeys, staleTimes } from '../lib/queryKeys'; import Card from '../components/Card'; import HandButton from '../components/HandButton'; @@ -279,6 +279,64 @@ function renderDetail(entry: LogEntry) { ); } +function LogStatsBar({ stats }: { stats: LogStatsResponse }) { + const commands = Object.entries(stats.by_command).sort((a, b) => b[1].total - a[1].total); + const rate = stats.total > 0 ? Math.round(stats.success_rate * 100) : 0; + const rateColor = rate >= 90 ? 'text-success' : rate >= 70 ? 'text-warning' : 'text-danger'; + + return ( +
+ {/* Success rate */} + +
+ Success Rate +
+
+ {rate}% +
+
+ {stats.total} total +
+
+ + {/* Top commands */} + {commands.slice(0, 4).map(([cmd, cs]) => ( + +
+ {cmd} +
+
+ {cs.total} +
+
+ {cs.ok > 0 && {cs.ok} ok} + {cs.error > 0 && {cs.error} err} + {cs.partial > 0 && {cs.partial} partial} +
+
+ ))} + + {/* Last operation */} + {stats.last_operation && ( + +
+ Last Op +
+
+ {stats.last_operation.cmd} +
+
+ {statusBadge(stats.last_operation.status)} +
+
+ )} +
+ ); +} + const PAGE_SIZES = [10, 25, 50] as const; function LogTable({ entries }: { entries: LogEntry[] }) { @@ -453,6 +511,13 @@ export default function LogPage() { staleTime: staleTimes.log, }); + const statsType = tab === 'audit' ? 'audit' : 'ops'; + const statsQuery = useQuery({ + queryKey: queryKeys.logStats(statsType, filters), + queryFn: () => api.getLogStats(statsType, filters), + staleTime: staleTimes.log, + }); + const opsEntries = opsQuery.data?.entries ?? []; const opsTotal = opsQuery.data?.total ?? 0; const opsTotalAll = opsQuery.data?.totalAll ?? 0; @@ -483,6 +548,7 @@ export default function LogPage() { const handleRefresh = () => { queryClient.invalidateQueries({ queryKey: ['log'] }); + queryClient.invalidateQueries({ queryKey: ['log-stats'] }); }; const handleClear = async () => { @@ -494,6 +560,7 @@ export default function LogPage() { await api.clearLog(tab); } queryClient.invalidateQueries({ queryKey: ['log'] }); + queryClient.invalidateQueries({ queryKey: ['log-stats'] }); toast('Log cleared', 'success'); } catch (e: any) { toast(e.message, 'error'); @@ -626,6 +693,10 @@ export default function LogPage() { + {statsQuery.data && statsQuery.data.total > 0 && ( + + )} + {tab === 'all' ? (