@@ -106,6 +106,21 @@ async def health_check():
106106 }
107107
108108
109+ @app .get ("/metrics/system" )
110+ async def get_system_telemetry ():
111+ """
112+ Exposes global infrastructure operational performance statistics.
113+ Calculates operational lifespan bounds, network ingestion volume, and channel load.
114+ """
115+ uptime_seconds = time .time () - PIPELINE_START_TIME
116+ return {
117+ "uptime_seconds" : round (uptime_seconds , 2 ),
118+ "total_processed_ticks" : TOTAL_PROCESSED_TICKS ,
119+ "active_websocket_channels" : sum (WS_CONCURRENT_TRACKER .values ()),
120+ "tracked_host_vectors" : len (WS_CONCURRENT_TRACKER ),
121+ }
122+
123+
109124@app .get ("/metrics/{symbol}" )
110125async def get_stream_metrics (symbol : str , request : Request ):
111126 """
@@ -160,7 +175,6 @@ async def websocket_endpoint(
160175 """
161176 global TOTAL_PROCESSED_TICKS
162177
163- # Defensive Control: Enforce cross-origin validation check to defend against CSWSH vectors
164178 request_origin = websocket .headers .get ("origin" )
165179 if request_origin not in ALLOWED_ORIGINS :
166180 SentinelLogger .error (
@@ -169,23 +183,20 @@ async def websocket_endpoint(
169183 await websocket .close (code = 1008 )
170184 return
171185
172- # Defensive Control: Enforce path token verification filtering out unauthorized character vectors
173186 if not re .match (r"^[A-Za-z0-9\-]+$" , symbol ):
174187 SentinelLogger .error (
175188 f"Malformed or non-whitelisted WebSocket stream parameter rejected: { symbol } "
176189 )
177190 await websocket .close (code = 1008 )
178191 return
179192
180- # Defensive Control: Enforce token parameter validation checking against cryptographic signatures
181193 if not authenticator .validate_handshake_token (token ):
182194 SentinelLogger .error (
183195 f"Unauthorized WebSocket handshake rejected: Invalid or missing token parameter."
184196 )
185197 await websocket .close (code = 1008 )
186198 return
187199
188- # Defensive Control: Enforce socket flood protection constraint rules per host identifier
189200 client_ip = websocket .client .host if websocket .client else "127.0.0.1"
190201 current_ws_count = WS_CONCURRENT_TRACKER .get (client_ip , 0 )
191202 if current_ws_count >= 5 :
@@ -195,7 +206,6 @@ async def websocket_endpoint(
195206 await websocket .close (code = 1008 )
196207 return
197208
198- # Register active allocation token increment
199209 WS_CONCURRENT_TRACKER [client_ip ] = current_ws_count + 1
200210
201211 await manager .connect (websocket , symbol )
@@ -278,7 +288,6 @@ async def websocket_endpoint(
278288 SentinelLogger .error (f"Internal Pipeline Telemetry Exception: { e } " )
279289 manager .disconnect (websocket , symbol )
280290 finally :
281- # Decouple registration matrix count states accurately during close cycles
282291 if client_ip in WS_CONCURRENT_TRACKER :
283292 WS_CONCURRENT_TRACKER [client_ip ] = max (
284293 0 , WS_CONCURRENT_TRACKER [client_ip ] - 1
0 commit comments