Step 10: 데이터 분석 및 통계 시스템 구현
주요 기능: - Statistics Service 마이크로서비스 구축 - 실시간 메트릭 수집 시스템 (Kafka 연동) - 시계열 데이터베이스 인터페이스 구현 - 데이터 집계 및 분석 엔진 - 사용자/시스템/이벤트 분석 API - WebSocket 기반 실시간 대시보드 - 알림 규칙 및 임계값 설정 - CSV 데이터 내보내기 구현된 컴포넌트: - MetricsCollector: Kafka 이벤트 메트릭 수집 - DataAggregator: 시간별/일별 데이터 집계 - TimeSeriesDB: 시계열 데이터 저장 인터페이스 - WebSocketManager: 실시간 데이터 스트리밍 - Analytics APIs: 다양한 분석 엔드포인트 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
33
services/statistics/backend/websocket_manager.py
Normal file
33
services/statistics/backend/websocket_manager.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""WebSocket Manager for real-time updates"""
|
||||
from typing import List
|
||||
from fastapi import WebSocket
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class WebSocketManager:
|
||||
"""Manages WebSocket connections"""
|
||||
|
||||
def __init__(self):
|
||||
self.active_connections: List[WebSocket] = []
|
||||
|
||||
async def connect(self, websocket: WebSocket):
|
||||
"""Accept WebSocket connection"""
|
||||
await websocket.accept()
|
||||
self.active_connections.append(websocket)
|
||||
logger.info(f"WebSocket connected. Total connections: {len(self.active_connections)}")
|
||||
|
||||
def disconnect(self, websocket: WebSocket):
|
||||
"""Remove WebSocket connection"""
|
||||
if websocket in self.active_connections:
|
||||
self.active_connections.remove(websocket)
|
||||
logger.info(f"WebSocket disconnected. Total connections: {len(self.active_connections)}")
|
||||
|
||||
async def broadcast(self, message: dict):
|
||||
"""Broadcast message to all connected clients"""
|
||||
for connection in self.active_connections:
|
||||
try:
|
||||
await connection.send_json(message)
|
||||
except Exception as e:
|
||||
logger.error(f"Error broadcasting to WebSocket: {e}")
|
||||
self.disconnect(connection)
|
||||
Reference in New Issue
Block a user