info('Connecting to Redis...'); // Total events in the main list $totalEvents = Redis::llen('realtime:events'); // Last N sample events $sampleCount = 10; $samples = Redis::lrange('realtime:events', -1 * $sampleCount, -1); $decodedSamples = []; $eventTypes = []; foreach ($samples as $s) { $d = json_decode($s, true); if (!is_array($d)) continue; $decodedSamples[] = $d; $evt = isset($d['event']) ? $d['event'] : (isset($d['event_type']) ? $d['event_type'] : 'unknown'); $eventTypes[] = $evt; } $typeCounts = array_count_values($eventTypes); arsort($typeCounts); // Extensions summary $extKeys = Redis::keys('realtime:ext:*'); $extCount = count($extKeys); $extList = []; foreach ($extKeys as $key) { $extId = substr($key, strlen('realtime:ext:')); $h = Redis::hgetall($key); $updated = isset($h['updated_at']) ? $h['updated_at'] : null; $extList[] = [ 'ext' => $extId, 'updated_at' => $updated, 'last_event' => isset($h['last_event']) ? $h['last_event'] : null, ]; } usort($extList, function($a, $b) { $ta = $a['updated_at'] ? strtotime($a['updated_at']) : 0; $tb = $b['updated_at'] ? strtotime($b['updated_at']) : 0; return $tb <=> $ta; }); $topExt = array_slice($extList, 0, 10); // Print summary $this->info('Redis realtime summary:'); $this->line(' Total events in list: ' . $totalEvents); $this->line(' Total tracked extensions: ' . $extCount); $this->info('Top event types:'); if (empty($typeCounts)) { $this->line(' (no recent events)'); } else { foreach ($typeCounts as $type => $count) { $this->line(' - ' . $type . ': ' . $count); } } $this->info('Sample events (most recent ' . count($decodedSamples) . '):'); foreach ($decodedSamples as $s) { $when = isset($s['timestamp']) ? $s['timestamp'] : null; $evt = isset($s['event']) ? $s['event'] : (isset($s['event_type']) ? $s['event_type'] : 'unknown'); $meta = isset($s['meta']) ? $s['meta'] : ''; $metaShort = strlen($meta) > 200 ? substr($meta,0,200) . '...' : $meta; $this->line(' [' . ($when ?? '') . '] ' . $evt . ' - ' . $metaShort); } $this->info('Top active extensions (most recently updated):'); if (empty($topExt)) { $this->line(' (none)'); } else { $display = []; foreach ($topExt as $row) { $lastType = '-'; if (!empty($row['last_event'])) { $d = json_decode($row['last_event'], true); if ($d && isset($d['event'])) $lastType = $d['event']; elseif ($d && isset($d['event_type'])) $lastType = $d['event_type']; } $display[] = [ 'extension' => $row['ext'], 'updated_at' => $row['updated_at'] ?: '-', 'last_event_type' => $lastType, ]; } $this->table(['extension', 'updated_at', 'last_event_type'], $display); } $this->info('Done.'); return 0; } catch (\Exception $e) { $this->error('Error reading Redis: ' . $e->getMessage()); return 1; } } }