Back to Demos

CCU Real-Time Monitor

Concurrent users tracking with multi-dimension aggregation

Real-time CCU (Last 60 seconds)

-60s-30sNow

Simulate Traffic

Production Code (Java)

// From ccu-realtime-monitor - CCUBean.java
@Scheduled(fixedRate = 1000)  // Update every second
public void updateCCUMetrics() {
    CCUData ccu = new CCUData();
    ccu.setTimestamp(System.currentTimeMillis());

    // Aggregate by platform
    Map<String, Long> byPlatform = connectionRegistry.stream()
        .collect(Collectors.groupingBy(
            Connection::getPlatform,
            Collectors.counting()
        ));

    // Aggregate by game
    Map<String, Long> byGame = connectionRegistry.stream()
        .collect(Collectors.groupingBy(
            Connection::getGame,
            Collectors.counting()
        ));

    // Aggregate by region
    Map<String, Long> byRegion = connectionRegistry.stream()
        .collect(Collectors.groupingBy(
            Connection::getRegion,
            Collectors.counting()
        ));

    ccu.setTotal(connectionRegistry.size());
    ccu.setByPlatform(byPlatform);
    ccu.setByGame(byGame);
    ccu.setByRegion(byRegion);

    // Broadcast to WebSocket subscribers
    ccuWebSocketHandler.broadcast(ccu);

    // Check alert threshold
    if (ccu.getTotal() >= alertThreshold) {
        notificationService.sendAlert("CCU reached " + ccu.getTotal());
    }
}