mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
Add real-time agent health monitoring and response utilities
Health Monitoring: - Add /controller/agents/health endpoint for efficient bulk health checks - Check all agents in one call with response time tracking - Update agent status in real-time (30s interval) - Show latency next to agent status in UI - Add collapsible "All Agents Health" panel in sidebar - Log console notifications when agents go online/offline Response Utilities: - Add unwrapAgentResponse() to consistently handle controller proxy format - Add isAgentMode() and getCurrentAgentName() helpers - Standardize error handling for agent responses UI Improvements: - Show response latency (ms) in agent selector dropdown - Health panel shows status + running modes for each agent - Better visual feedback for agent status changes
This commit is contained in:
@@ -267,6 +267,68 @@ def get_agent_status(agent_id: int):
|
||||
}), 503
|
||||
|
||||
|
||||
@controller_bp.route('/agents/health', methods=['GET'])
|
||||
def check_all_agents_health():
|
||||
"""
|
||||
Check health of all registered agents in one call.
|
||||
|
||||
More efficient than checking each agent individually.
|
||||
Returns health status, response time, and running modes for each agent.
|
||||
"""
|
||||
agents_list = list_agents(active_only=True)
|
||||
results = []
|
||||
|
||||
for agent in agents_list:
|
||||
result = {
|
||||
'id': agent['id'],
|
||||
'name': agent['name'],
|
||||
'healthy': False,
|
||||
'response_time_ms': None,
|
||||
'running_modes': [],
|
||||
'error': None
|
||||
}
|
||||
|
||||
try:
|
||||
client = create_client_from_agent(agent)
|
||||
|
||||
# Time the health check
|
||||
start_time = time.time()
|
||||
is_healthy = client.health_check()
|
||||
response_time = (time.time() - start_time) * 1000
|
||||
|
||||
result['healthy'] = is_healthy
|
||||
result['response_time_ms'] = round(response_time, 1)
|
||||
|
||||
if is_healthy:
|
||||
# Update last_seen in database
|
||||
update_agent(agent['id'], update_last_seen=True)
|
||||
|
||||
# Also fetch running modes
|
||||
try:
|
||||
status = client.get_status()
|
||||
result['running_modes'] = status.get('running_modes', [])
|
||||
result['running_modes_detail'] = status.get('running_modes_detail', {})
|
||||
except Exception:
|
||||
pass # Status fetch is optional
|
||||
|
||||
except AgentConnectionError as e:
|
||||
result['error'] = f'Connection failed: {str(e)}'
|
||||
except AgentHTTPError as e:
|
||||
result['error'] = f'HTTP error: {str(e)}'
|
||||
except Exception as e:
|
||||
result['error'] = str(e)
|
||||
|
||||
results.append(result)
|
||||
|
||||
return jsonify({
|
||||
'status': 'success',
|
||||
'timestamp': datetime.now(timezone.utc).isoformat(),
|
||||
'agents': results,
|
||||
'total': len(results),
|
||||
'healthy_count': sum(1 for r in results if r['healthy'])
|
||||
})
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Proxy Operations - Forward requests to agents
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user