Visualization
This section covers the real-time monitoring, dashboard, and performance visualization capabilities in the Kailash SDK.
Overview
The visualization system provides comprehensive real-time monitoring and performance analysis for workflow execution:
Real-time Dashboards: Live monitoring with streaming metrics
Performance Reports: Multi-format comprehensive reports
Interactive Charts: Chart.js integration for web dashboards
API Access: REST and WebSocket endpoints for custom integrations
Resource Monitoring: CPU, memory, and I/O tracking
Bottleneck Analysis: Automatic performance issue detection
Real-time Dashboard
The core component for live workflow monitoring with background metrics collection.
- class kailash.visualization.dashboard.RealTimeDashboard(task_manager: TaskManager, config: DashboardConfig | None = None)[source]
Bases:
objectReal-time dashboard for workflow monitoring.
This class provides comprehensive real-time monitoring capabilities including live metrics collection, interactive visualizations, and status reporting for workflow execution.
- Usage:
dashboard = RealTimeDashboard(task_manager) dashboard.start_monitoring() # Dashboard runs in background dashboard.generate_live_report(“output.html”) dashboard.stop_monitoring()
- Parameters:
task_manager (TaskManager)
config (DashboardConfig | None)
- __init__(task_manager: TaskManager, config: DashboardConfig | None = None)[source]
Initialize real-time dashboard.
- Parameters:
task_manager (TaskManager) – TaskManager instance for data access
config (DashboardConfig | None) – Dashboard configuration options
- start_monitoring(run_id: str | None = None)[source]
Start real-time monitoring for a workflow run.
- Parameters:
run_id (str | None) – Specific run to monitor, or None for latest
- add_metrics_callback(callback: Any)[source]
Add callback for metrics updates.
- Parameters:
callback (Any) – Function that takes LiveMetrics as argument
- add_status_callback(callback: Any)[source]
Add callback for status changes.
- Parameters:
callback (Any) – Function that takes (event_type, count) as arguments
- get_current_metrics() LiveMetrics | None[source]
Get the most recent metrics.
- Return type:
LiveMetrics | None
- get_metrics_history(minutes: int | None = None) list[LiveMetrics][source]
Get metrics history for specified time period.
- Parameters:
minutes (int | None) – Number of minutes of history to return
- Returns:
List of metrics within time period
- Return type:
Dashboard Configuration
Configuration options for customizing dashboard behavior and appearance.
- class kailash.visualization.dashboard.DashboardConfig(update_interval: float = 1.0, max_history_points: int = 100, auto_refresh: bool = True, show_completed: bool = True, show_failed: bool = True, theme: str = 'light')[source]
Bases:
objectConfiguration for dashboard components.
- Variables:
update_interval (float) – Seconds between dashboard updates
max_history_points (int) – Maximum data points to keep in memory
auto_refresh (bool) – Whether to automatically refresh data
show_completed (bool) – Whether to show completed tasks
show_failed (bool) – Whether to show failed tasks
theme (str) – Dashboard color theme (‘light’ or ‘dark’)
- Parameters:
Live Metrics
Data models for real-time performance metrics.
- class kailash.visualization.dashboard.LiveMetrics(timestamp: datetime = <factory>, active_tasks: int = 0, completed_tasks: int = 0, failed_tasks: int = 0, total_cpu_usage: float = 0.0, total_memory_usage: float = 0.0, throughput: float = 0.0, avg_task_duration: float = 0.0)[source]
Bases:
objectContainer for live performance metrics.
- Variables:
timestamp (datetime.datetime) – When metrics were collected
active_tasks (int) – Number of currently running tasks
completed_tasks (int) – Number of completed tasks
failed_tasks (int) – Number of failed tasks
total_cpu_usage (float) – System-wide CPU usage percentage
total_memory_usage (float) – System-wide memory usage in MB
throughput (float) – Tasks completed per minute
avg_task_duration (float) – Average task execution time
- Parameters:
Performance Reporter
Generate comprehensive performance reports in multiple formats.
- class kailash.visualization.reports.WorkflowPerformanceReporter(task_manager: TaskManager, config: ReportConfig | None = None)[source]
Bases:
objectComprehensive workflow performance report generator.
This class provides detailed performance analysis and reporting capabilities for workflow executions, including insights, recommendations, and comparative analysis across multiple runs.
- Usage:
reporter = WorkflowPerformanceReporter(task_manager) report = reporter.generate_report(run_id, output_path=”report.html”)
- Parameters:
task_manager (TaskManager)
config (ReportConfig | None)
- __init__(task_manager: TaskManager, config: ReportConfig | None = None)[source]
Initialize performance reporter.
- Parameters:
task_manager (TaskManager) – TaskManager instance for data access
config (ReportConfig | None) – Report configuration options
Report Formats
Supported output formats for performance reports.
- class kailash.visualization.reports.ReportFormat(value)[source]
Bases:
EnumSupported report output formats.
- HTML = 'html'
- MARKDOWN = 'markdown'
- JSON = 'json'
- PDF = 'pdf'
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
Performance Insights
Structured performance analysis and recommendations.
- class kailash.visualization.reports.PerformanceInsight(category: str, severity: str, title: str, description: str, recommendation: str, metrics: dict[str, ~typing.Any]=<factory>)[source]
Bases:
objectContainer for performance insights and recommendations.
Dashboard API
REST API interface for accessing metrics programmatically.
- class kailash.visualization.api.SimpleDashboardAPI(task_manager: TaskManager, dashboard_config: DashboardConfig | None = None)[source]
Bases:
objectSimplified API interface for dashboard functionality without FastAPI.
This class provides dashboard API functionality using standard Python libraries for environments where FastAPI is not available or desired.
- Parameters:
task_manager (TaskManager)
dashboard_config (DashboardConfig | None)
- __init__(task_manager: TaskManager, dashboard_config: DashboardConfig | None = None)[source]
Initialize simple API interface.
- Parameters:
task_manager (TaskManager) – TaskManager instance for data access
dashboard_config (DashboardConfig | None) – Configuration for dashboard components
- generate_report(run_id: str, format: str = 'html', output_path: str | Path | None = None, compare_runs: list[str] | None = None) Path[source]
Generate performance report.
WebSocket Server
FastAPI-based server for real-time metrics streaming.
Note
This component requires FastAPI to be installed. Install with: pip install fastapi uvicorn
- class kailash.visualization.api.DashboardAPIServer(task_manager: TaskManager, dashboard_config: DashboardConfig | None = None, cors_origins: list[str] | None = None, require_auth: bool = True, auth_config: Any = None, external_auth_reason: str | None = None, auth_exempt_paths: list[str] | None = None)[source]
Bases:
objectFastAPI server for dashboard API endpoints.
This class provides a complete REST API server for accessing real-time workflow performance data and dashboard components.
Authentication fails CLOSED (#2112):
require_authdefaults toTrueand construction raisesServerAuthNotConfiguredErrorunless a credential source is configured.- Usage:
# export KAILASH_JWT_SECRET=<at least 32 bytes> api_server = DashboardAPIServer(task_manager) api_server.start_server(host=”0.0.0.0”, port=8000)
# Or, to run without authentication – an explicit opt-out that logs a # loud WARN naming the exposure: api_server = DashboardAPIServer(task_manager, require_auth=False)
- Parameters:
task_manager (TaskManager)
dashboard_config (DashboardConfig | None)
require_auth (bool)
auth_config (Any)
external_auth_reason (str | None)
- __init__(task_manager: TaskManager, dashboard_config: DashboardConfig | None = None, cors_origins: list[str] | None = None, require_auth: bool = True, auth_config: Any = None, external_auth_reason: str | None = None, auth_exempt_paths: list[str] | None = None)[source]
Initialize API server.
- Parameters:
task_manager (TaskManager) – TaskManager instance for data access
dashboard_config (DashboardConfig | None) – Configuration for dashboard components
cors_origins (list[str] | None) – Allowed CORS origins. Defaults to
[](no cross-origin browser access), which is what this server has always used; supplying a list is what makes the CORS layer actually usable from a dashboard front-end.require_auth (bool) –
Whether every request must be authenticated. Defaults to ``True`` (fail-closed) and this is a BREAKING change – see
kailash.utils.server_auth. This class builds its own FastAPI application and ships its ownstart_server()under uvicorn, so it is a server in its own right: reachable withoutWorkflowServer, withoutcreate_gateway(), and untouched by the six surfaces PR #2100 closed. Un-gated it servedGET /api/v1/runs,GET /api/v1/runs/{id}/tasks, report downloads and two websocket streams to anonymous callers – run history and per-run task breakdowns describing what the system runs and when. There is no execute route here, so this is anonymous DISCLOSURE rather than anonymous code execution.Construction RAISES
ServerAuthNotConfiguredErrorwhen no credential source is configured, rather than serving that surface openly. SetKAILASH_JWT_SECRET(orKAILASH_API_KEY_<NAME>, or passauth_config=) to configure one. Passrequire_auth=Falseto run without authentication – an explicit opt-out that logs a loud WARN.auth_config (Any) – Explicit
JWTConfig(or adictof its fields) to authenticate with, bypassing environment lookup.external_auth_reason (str | None) – Non-empty string declaring that an ASGI middleware OUTSIDE this server authenticates every request, so this server installs none. A blank string is rejected – a reason that names nothing is an undocumented hole.
auth_exempt_paths (list[str] | None) – Extra paths exempt from authentication, on top of the health-probe defaults.
/docs,/openapi.jsonand the/api/v1/*routes are NOT exempt by default; each describes or exposes the protected surface.
- Raises:
ImportError – FastAPI is not installed.
ServerAuthNotConfiguredError –
require_auth=Trueand no credential source is configured.
Performance Visualizer
Static performance analysis and chart generation.
- class kailash.visualization.performance.PerformanceVisualizer(task_manager: TaskManager)[source]
Bases:
objectCreates performance reports from task execution metrics.
Generates Markdown with tables and Mermaid bar charts — renders natively in GitHub, VS Code, JetBrains, and any Markdown viewer.
- Parameters:
task_manager (TaskManager)
- __init__(task_manager: TaskManager)[source]
- Parameters:
task_manager (TaskManager)
Usage Examples
Basic Real-time Monitoring
from kailash.visualization.dashboard import RealTimeDashboard, DashboardConfig
from kailash.tracking import TaskManager
from kailash.runtime.local import LocalRuntime
# Setup components
task_manager = TaskManager()
config = DashboardConfig(
update_interval=1.0,
max_history_points=100,
auto_refresh=True,
theme="light"
)
# Create dashboard
dashboard = RealTimeDashboard(task_manager, config)
# Start monitoring
dashboard.start_monitoring()
# Execute workflow with monitoring
with LocalRuntime() as runtime:
results, run_id = runtime.execute(workflow, task_manager)
# Generate live dashboard
dashboard.generate_live_report("dashboard.html", include_charts=True)
dashboard.stop_monitoring()
Performance Report Generation
from kailash.visualization.reports import WorkflowPerformanceReporter, ReportFormat
# Create reporter
reporter = WorkflowPerformanceReporter(task_manager)
# Generate comprehensive HTML report
report_path = reporter.generate_report(
run_id,
output_path="performance_report.html",
format=ReportFormat.HTML,
compare_runs=[previous_run_id]
)
# Generate Markdown report
md_report = reporter.generate_report(
run_id,
format=ReportFormat.MARKDOWN
)
API-based Monitoring
from kailash.visualization.api import SimpleDashboardAPI
# Create API interface
api = SimpleDashboardAPI(task_manager)
api.start_monitoring()
# Get current metrics
metrics = api.get_current_metrics()
print(f"Active tasks: {metrics['active_tasks']}")
# Get historical data
history = api.get_metrics_history(minutes=30)
# Stop monitoring
api.stop_monitoring()
WebSocket Streaming Server
from kailash.visualization.api import DashboardAPIServer
import asyncio
# Create server
server = DashboardAPIServer(task_manager, port=8000)
# Start server (runs async)
async def run_server():
await server.start()
# In your client (JavaScript):
# const ws = new WebSocket('ws://localhost:8000/api/v1/metrics/stream');
# ws.onmessage = (event) => {
# const metrics = JSON.parse(event.data);
# // Update dashboard with real-time metrics
# };
Real-time Callbacks
# Add custom callbacks for real-time events
def on_metrics_update(metrics):
print(f"CPU: {metrics.total_cpu_usage:.1f}%, Memory: {metrics.total_memory_usage:.1f}MB")
def on_status_change(event_type, count):
if event_type == "task_completed":
print(f"✅ {count} task(s) completed")
elif event_type == "task_failed":
print(f"❌ {count} task(s) failed")
dashboard.add_metrics_callback(on_metrics_update)
dashboard.add_status_callback(on_status_change)
Dashboard Features
The real-time dashboard provides:
- Live Metrics
Active, completed, and failed task counts
Real-time CPU and memory usage
Throughput metrics (tasks per minute)
I/O statistics and data transfer rates
- Interactive Charts
Timeline charts with Chart.js integration
Resource usage graphs over time
Task status progression visualization
Performance comparison charts
- Responsive Design
Mobile-friendly layout
Auto-refresh capabilities
Dark/light theme support
Customizable update intervals
- Export Options
HTML dashboards with embedded JavaScript
JSON metrics logs for external analysis
Markdown reports for documentation
PNG/SVG chart exports (with matplotlib)
Architecture
The visualization system follows a modular architecture:
graph TB
subgraph "Real-time Layer"
A[RealTimeDashboard]
B[LiveMetrics]
C[DashboardConfig]
end
subgraph "Reporting Layer"
D[WorkflowPerformanceReporter]
E[PerformanceInsight]
F[ReportFormat]
end
subgraph "API Layer"
G[SimpleDashboardAPI]
H[DashboardAPIServer]
I[WebSocket Streaming]
end
subgraph "Static Analysis"
J[PerformanceVisualizer]
K[Chart Generation]
L[Metrics Analysis]
end
A --> B
A --> C
A --> G
D --> E
D --> F
G --> H
H --> I
J --> K
J --> L
A --> D
G --> J
Best Practices
- Real-time Monitoring
Use appropriate update intervals (1-5 seconds for active monitoring)
Limit history points to prevent memory issues (100-500 points)
Stop monitoring when done to free resources
Use callbacks for custom event handling
- Performance Reports
Generate reports after workflow completion
Compare multiple runs to identify trends
Include relevant run metadata and context
Use appropriate output formats for your use case
- API Integration
Use WebSocket streaming for real-time dashboards
Implement proper error handling and reconnection
Rate limit API calls to prevent performance impact
Cache metrics data for better performance
- Resource Management
Monitor system resources during metrics collection
Use background threads to avoid blocking workflow execution
Implement proper cleanup and resource disposal
Consider storage requirements for long-running monitoring