/** * Tool: Dauer-/Stresstest — Langzeitmessung von Verlust und Latenz. * * Läuft nativ als Foreground-Service, damit Android den Lauf nicht beendet. * Die Dauer wird als Parameter vorgegeben; run() wartet auf das Ergebnis. */ import { scanner } from '../../scanner'; import type { MeasureStatus, Tool } from '../types'; export const stressTestTool: Tool = { id: 'stresstest', category: 'netzwerk', name: 'Dauer-/Stresstest', icon: 'gauge', description: 'Langzeitmessung: Paketverlust und Latenz über einen Zeitraum.', scope: 'protocol', params: [ { key: 'host', label: 'Ziel', type: 'text', default: '192.168.1.1' }, { key: 'duration', label: 'Dauer', type: 'select', default: '300', options: [ { value: '60', label: '1 Minute' }, { value: '300', label: '5 Minuten' }, { value: '900', label: '15 Minuten' }, { value: '3600', label: '1 Stunde' }, ], }, ], async run(ctx) { const host = String(ctx.params.host || '192.168.1.1'); const durationSec = Number(ctx.params.duration || 300); const { runId } = await scanner.startStressTest({ host, durationSec }); // Auf das Ende des Laufs warten (Foreground-Service misst weiter) await new Promise((r) => setTimeout(r, durationSec * 1000)); const res = await scanner.stopStressTest({ runId }); let status: MeasureStatus = 0; if (res.lossPct > 0 || res.maxMs > 100) status = 1; if (res.lossPct >= 5 || res.maxMs > 500) status = 2; return { label: `${host}: ${res.lossPct}% Verlust über ${Math.round(durationSec / 60)} min`, result: { host, dauerSekunden: durationSec, messpunkte: res.samples, verlustProzent: res.lossPct, avgMs: res.avgMs, maxMs: res.maxMs, }, measureStatus: status, }; }, };