Current section
Files
Jump to
Current section
Files
lib/superintelligence_web/controllers/startup_controller.ex
defmodule SuperintelligenceWeb.StartupController do
use SuperintelligenceWeb, :controller
def show(conn, _params) do
# Get comprehensive startup data
timer_report = if Process.whereis(Superintelligence.StartupTimer) do
Superintelligence.StartupTimer.report()
else
"Startup timer not available"
end
profiler_report = if Process.whereis(Superintelligence.StartupProfiler) do
Superintelligence.StartupProfiler.generate_report()
else
"Profiler not available"
end
orchestrator_status = if Process.whereis(Superintelligence.StartupOrchestrator) do
Superintelligence.StartupOrchestrator.get_status()
else
%{}
end
health_status = if Process.whereis(Superintelligence.HealthMonitor) do
Superintelligence.HealthMonitor.get_health_status()
else
%{}
end
resource_usage = if Process.whereis(Superintelligence.ResourceManager) do
Superintelligence.ResourceManager.get_usage()
else
%{}
end
telemetry_metrics = if Process.whereis(Superintelligence.TelemetryReporter) do
Superintelligence.TelemetryReporter.get_metrics()
else
%{}
end
worker_pool_status = if Process.whereis(Superintelligence.WorkerPool.PoolManager) do
Superintelligence.WorkerPool.get_status()
else
%{}
end
html = """
<!DOCTYPE html>
<html>
<head>
<title>Startup Execution Flow</title>
<style>
body { font-family: monospace; background: #1a1a1a; color: #00ff00; padding: 20px; }
pre { background: #0a0a0a; padding: 20px; border-radius: 5px; overflow-x: auto; }
.worker { margin: 10px 0; padding: 10px; background: #2a2a2a; border-radius: 3px; }
h2 { color: #00ffff; }
h3 { color: #ffff00; margin-top: 20px; }
.flow { margin: 20px 0; }
.step { margin-left: 20px; padding: 5px 0; }
.section { margin: 20px 0; padding: 15px; background: #0f0f0f; border-radius: 8px; border: 1px solid #333; }
</style>
</head>
<body>
<h1>π Superintelligence Startup Execution Flow</h1>
<h2>π Startup Performance</h2>
<div class="section">
<h3>Basic Timing</h3>
<pre>#{html_escape(timer_report)}</pre>
</div>
<div class="section">
<h3>π₯ Advanced Profiler Report</h3>
<pre style="font-size: 12px;">#{html_escape(profiler_report)}</pre>
</div>
<div class="section">
<h3>π Orchestrator Status</h3>
<pre>#{html_escape(inspect(orchestrator_status, pretty: true))}</pre>
</div>
<div class="section">
<h3>π₯ Health Monitor</h3>
<pre>#{html_escape(inspect(health_status, pretty: true))}</pre>
</div>
<div class="section">
<h3>ποΈ Resource Usage</h3>
<pre>#{html_escape(inspect(resource_usage, pretty: true))}</pre>
</div>
<div class="section">
<h3>π‘ Telemetry Metrics</h3>
<pre>#{html_escape(inspect(telemetry_metrics, pretty: true))}</pre>
</div>
<div class="section">
<h3>π· Worker Pool Status</h3>
<pre>#{html_escape(inspect(worker_pool_status, pretty: true))}</pre>
</div>
<h2>π Execution Flow</h2>
<div class="flow">
<div class="step">1. mix run β Elixir VM starts</div>
<div class="step">2. Superintelligence.Application.start/2</div>
<div class="step"> ββ π StartupProfiler (tracks performance)</div>
<div class="step"> ββ π StartupOrchestrator (manages dependencies)</div>
<div class="step"> ββ β±οΈ StartupTimer (basic timing)</div>
<div class="step"> ββ π‘ TelemetryReporter (metrics collection)</div>
<div class="step"> ββ π Registry (process discovery)</div>
<div class="step"> ββ ποΈ ResourceManager (CPU/memory/connections)</div>
<div class="step"> ββ π₯ HealthMonitor (circuit breakers)</div>
<div class="step"> ββ π HotReloader (zero-downtime updates)</div>
<div class="step"> ββ π· WorkerPool (dynamic scaling)</div>
<div class="step"> β ββ Auto-scaling based on load</div>
<div class="step"> β ββ Task prioritization</div>
<div class="step"> β ββ Health checks</div>
<div class="step"> ββ π Phoenix.Endpoint (web server)</div>
<div class="step"> ββ π Telemetry (monitoring)</div>
<div class="step">3. Orchestrator initializes components:</div>
<div class="step"> ββ Dependency graph resolution</div>
<div class="step"> ββ Parallel initialization stages</div>
<div class="step"> ββ Health check registration</div>
<div class="step"> ββ Resource quota allocation</div>
<div class="step"> ββ Telemetry alert configuration</div>
<div class="step">4. Bandit binds to port 4000</div>
<div class="step">5. System ready with advanced features! π</div>
</div>
<h2>π― Advanced Features</h2>
<div class="section">
<ul style="list-style: none; padding-left: 0;">
<li>β
Dependency graph resolution with topological sorting</li>
<li>β
Parallel initialization in optimized stages</li>
<li>β
Resource pooling with dynamic scaling</li>
<li>β
Circuit breakers for fault tolerance</li>
<li>β
Health monitoring with auto-recovery</li>
<li>β
Performance profiling with flame graphs</li>
<li>β
Hot-reload with canary/blue-green/rolling deployments</li>
<li>β
Real-time telemetry and alerting</li>
<li>β
Memory and CPU resource management</li>
<li>β
Task prioritization and queuing</li>
</ul>
</div>
<p><a href="/" style="color: #00ffff;">β Back to Home</a></p>
</body>
</html>
"""
conn
|> put_resp_content_type("text/html")
|> send_resp(200, html)
end
defp get_worker_status do
case Registry.select(Superintelligence.Registry, [{{:"$1", :"$2", :"$3"}, [{:==, {:element, 1, :"$1"}, :worker}], [:"$2"]}]) do
pids when is_list(pids) ->
Enum.map(pids, fn pid ->
try do
GenServer.call(pid, :status, 1000)
catch
:exit, _ -> nil
end
end)
|> Enum.filter(&(&1))
_ -> []
end
end
defp format_workers_html(workers) do
if Enum.empty?(workers) do
"<p>No workers active</p>"
else
workers
|> Enum.map(fn worker ->
"""
<div class="worker">
<strong>#{worker.name}</strong><br>
PID: #{inspect(worker.pid)}<br>
Uptime: #{worker.uptime_seconds}s
</div>
"""
end)
|> Enum.join("")
end
end
defp html_escape(text) do
text
|> String.replace("&", "&")
|> String.replace("<", "<")
|> String.replace(">", ">")
|> String.replace("\"", """)
|> String.replace("'", "'")
end
end