// src/pages/Encryption.jsx import { useQuery } from '@tanstack/react-query'; import { ShieldAlert, ShieldCheck, TrendingUp, AlertTriangle, Loader2 } from 'lucide-react'; import { queryEncryptionDetail } from '@/api/prometheusExtended'; import TimeSeriesChart from '@/components/charts/TimeSeriesChart'; import clsx from 'clsx'; const REFRESH = 30_000; function EncryptionBar({ pct }) { const enc = Math.min(pct ?? 0, 100); const color = enc > 80 ? 'bg-crit' : enc > 50 ? 'bg-warn' : 'bg-ok'; const textC = enc > 80 ? 'text-crit' : enc > 50 ? 'text-warn' : 'text-ok'; return (
{enc.toFixed(1)}%
); } function TrendBadge({ level }) { const l = level ?? 0; if (l === 0) return Stable; if (l === 1) return Rising; return Spike; } export default function EncryptionPage() { const { data: vms = [], isLoading } = useQuery({ queryKey: ['encryption-detail'], queryFn: queryEncryptionDetail, refetchInterval: REFRESH, }); const anomalies = vms.filter((v) => (v.pctEncrypted ?? 0) > 50); const highAlert = vms.filter((v) => (v.pctEncrypted ?? 0) > 80); const avgPct = vms.length ? vms.reduce((s, v) => s + (v.pctEncrypted ?? 0), 0) / vms.length : 0; return (
{[ { label: 'VMs Monitored', value: vms.length, icon: ShieldAlert, color: 'accent' }, { label: 'Anomalies (>50%)', value: anomalies.length, icon: AlertTriangle, color: anomalies.length ? 'warn' : 'ok' }, { label: 'High Alert (>80%)', value: highAlert.length, icon: TrendingUp, color: highAlert.length ? 'crit' : 'ok' }, { label: 'Avg Encryption', value: `${avgPct.toFixed(1)}%`, icon: ShieldCheck, color: avgPct > 60 ? 'warn' : 'ok' }, ].map((s) => (

{s.label}

{s.value}

))}
{anomalies.length > 0 && ( `${v.toFixed(1)}%`} refLines={[{ value: 80, label: 'High alert', color: 'crit' }, { value: 50, label: 'Warning', color: 'warn' }]} transform={(result) => result[0]?.values.map(([ts, v]) => ({ ts: ts * 1000, 'Encrypted %': parseFloat(v) })) ?? []} height={180} /> )}

VM Encryption Status

{isLoading && ( )} {!isLoading && vms.map((vm) => ( ))} {!isLoading && vms.length === 0 && ( )}
VM VPG Encryption % Trend IO Ops Write
{vm.name} {vm.vpgName} {vm.ioOps != null ? Math.round(vm.ioOps).toLocaleString() : '—'} {vm.writeMb != null ? `${vm.writeMb.toFixed(2)} MB` : '—'}

No encryption stats available

); }