read(); if (($status['configured'] ?? false) && ! ($status['stale'] ?? true)) { $now = now(); $rows = []; foreach ($status['peers'] ?? [] as $peer) { $rows[] = [ 'peer_pubkey' => (string) ($peer['pubkey'] ?? ''), 'peer_name' => ($peer['name'] ?? '') !== '' ? (string) $peer['name'] : null, 'rx' => (int) ($peer['rx'] ?? 0), 'tx' => (int) ($peer['tx'] ?? 0), 'sampled_at' => $now, ]; } if ($rows !== []) { WgTrafficSample::insert($rows); } } $retention = max(1, (int) $this->option('retention')); WgTrafficSample::where('sampled_at', '<', now()->subDays($retention))->delete(); return self::SUCCESS; } }