Dashboard Package

Dashboard UI components and utilities. This documentation is auto-generated from Python docstrings.

Package Overview

HemoStat Dashboard Package

Real-time Streamlit dashboard for monitoring HemoStat container health system. Displays live container metrics, active issues, remediation history, and event timeline.

Main Application

Streamlit-based monitoring dashboard.

HemoStat Dashboard Main Application

Real-time Streamlit dashboard for monitoring HemoStat container health system. Displays live container metrics, active issues, remediation history, and event timeline with auto-refresh every 5 seconds.

dashboard.app.check_redis_connection()[source]

Test Redis connection and return status.

Returns:

True if Redis is connected, False otherwise

Return type:

bool

dashboard.app.main()[source]

Main dashboard application entry point.

Initializes the dashboard, renders sidebar, header, content, and footer.

Render dashboard footer with version and status information.

Displays HemoStat version and last update timestamp.

dashboard.app.render_header()[source]

Render dashboard header with title and connection status.

Displays main title, subtitle with current timestamp, and connection status indicator.

dashboard.app.render_live_content()[source]

Render auto-refreshing dashboard content.

Uses st.fragment with dynamic run_every interval tied to session state. Fetches data from Redis and renders all dashboard tabs. Tabs are outside fragment to preserve selection across refreshes.

dashboard.app.render_sidebar()[source]

Render sidebar with system status, controls, and links.

Displays Redis connection status, refresh controls, settings, and helpful links to documentation and repositories.

UI Components

Reusable dashboard components for displaying metrics and events.

Dashboard UI Components Module

Provides reusable Streamlit components for rendering dashboard visualizations. Includes metrics cards, health grids, issue feeds, history tables, and timelines.

dashboard.components.format_timestamp(iso_timestamp)[source]

Format ISO timestamp to relative or absolute time string in Eastern Time (GMT-5).

Converts ISO timestamps to relative time for recent events (“2 minutes ago”, “1 hour ago”) and absolute time for older events (“Jan 3, 10:30 AM EST”).

Parameters:

iso_timestamp (str) – ISO format timestamp string

Returns:

Formatted timestamp string in Eastern Time or “Unknown” if invalid

Return type:

str

dashboard.components.get_event_type_icon(event_type)[source]

Map event type to text indicator.

Returns text indicator for different event types: - health_alert: [ALERT] - remediation: [REMEDIATION] - false_alarm: [FALSE ALARM] - unknown: [EVENT]

Parameters:

event_type (str) – Event type string

Returns:

Text indicator

Return type:

str

dashboard.components.get_severity_emoji(severity)[source]

Map severity level to text indicator.

Returns text indicator for different severity levels: - critical: [CRITICAL] - high: [HIGH] - medium: [MEDIUM] - low: [LOW] - unknown: [UNKNOWN]

Parameters:

severity (str) – Severity level string

Returns:

Text indicator

Return type:

str

dashboard.components.get_status_color(status)[source]

Map status string to hex color code.

Returns color codes for different status values: - success/healthy: green - failed/unhealthy: red - rejected: orange - unknown: gray

Parameters:

status (str) – Status string

Returns:

Hex color code

Return type:

str

dashboard.components.render_active_issues(events)[source]

Render active issues that need attention.

Displays failed/rejected remediations and recent health alerts with severity indicators. Uses expanders for detailed information.

Parameters:

events (list[dict]) – List of event dictionaries from Redis

dashboard.components.render_health_grid(events)[source]

Render container health status in a grid layout.

Displays a table of containers with their latest status, CPU/memory percentages from hemostat:stats:* keys (preferred) or event data (fallback), and last update timestamp. Uses color coding for status (green=healthy, red=unhealthy, blue=remediated).

Parameters:

events (list[dict]) – List of event dictionaries from Redis

dashboard.components.render_metrics_cards(remediation_stats, false_alarm_count, active_containers)[source]

Render key metrics in a row of cards.

Displays four metric cards showing total remediations, success rate, false alarms, and active containers. Uses color coding for success rate (green >80%, yellow 50-80%, red <50%).

Parameters:
  • remediation_stats (dict[str, Any]) – Dictionary with remediation statistics

  • false_alarm_count (int) – Number of false alarm events

  • active_containers (int) – Number of active containers

dashboard.components.render_remediation_history(events)[source]

Render table of remediation attempts with filtering.

Displays all remediation events with columns for timestamp, container, action, status, reason, and confidence. Includes filters for status, container, and time range. Reasons can be expanded to view full text.

Parameters:

events (list[dict]) – List of remediation event dictionaries from Redis

dashboard.components.render_timeline(events, max_events=100)[source]

Render chronological timeline of all events with graph visualization.

Displays events in reverse chronological order (newest first) with type indicators, container names, and expandable details. Also shows a timeline graph of event frequency.

Parameters:
  • events (list[dict]) – List of event dictionaries from Redis

  • max_events (int) – Maximum number of events to display (default: 100)

Data Fetching Utilities

Redis data fetching and aggregation utilities.

Dashboard Data Fetcher Module

Provides Redis data access layer with efficient caching for dashboard operations. Uses Streamlit caching decorators to minimize Redis polling and improve performance.

dashboard.data_fetcher.get_active_containers()

Fetch list of active container IDs from Redis with 5-second cache.

Scans Redis for keys matching hemostat:state:container:* pattern and extracts container IDs. Uses SCAN instead of KEYS for production safety.

Returns:

List of active container IDs

Return type:

list[str]

dashboard.data_fetcher.get_all_container_stats()

Fetch all container statistics from Redis with 5-second cache.

Scans Redis for keys matching hemostat:stats:* pattern and retrieves parsed stats for each container. Uses SCAN for production safety.

Returns:

Dictionary mapping container IDs to their stats

Return type:

dict[str, dict[str, Any]]

dashboard.data_fetcher.get_all_events(limit=1000)

Fetch all events from Redis with 5-second cache.

Retrieves events from the hemostat:events:all list, parses JSON, and returns sorted by timestamp (newest first). Handles missing keys and malformed JSON gracefully.

Parameters:

limit (int) – Maximum number of events to retrieve (default: 1000)

Returns:

List of event dictionaries sorted by timestamp (newest first)

Return type:

list[dict]

dashboard.data_fetcher.get_container_stats(container_id)

Fetch container statistics from Redis with 5-second cache.

Retrieves stats from hemostat:state:container:{container_id} key, parses JSON, and returns as dictionary. Returns None if key doesn’t exist or has expired.

Parameters:

container_id (str) – Container ID to fetch stats for

Returns:

Container stats dictionary or None if not found

Return type:

dict[str, Any] | None

dashboard.data_fetcher.get_events_by_type(event_type, limit=1000)

Fetch events of a specific type from Redis with 5-second cache.

Retrieves events from hemostat:events:{event_type} list, parses JSON, and returns as list. Handles missing keys gracefully.

Parameters:
  • event_type (str) – Type of events to fetch (e.g., ‘remediation_complete’, ‘false_alarm’)

  • limit (int) – Maximum number of events to retrieve (default: 1000)

Returns:

List of event dictionaries of the specified type

Return type:

list[dict]

dashboard.data_fetcher.get_false_alarm_count()

Count false alarm events from Redis with 5-second cache.

Uses LLEN to efficiently count events in hemostat:events:false_alarm list without fetching all events.

Returns:

Number of false alarm events

Return type:

int

dashboard.data_fetcher.get_redis_client()

Get or create a cached Redis client for long-lived connections.

Loads Redis configuration from environment variables and establishes a connection with string response decoding enabled. Tests connection on first initialization.

Returns:

Connected Redis client instance with decode_responses=True

Return type:

redis.Redis

Raises:

redis.ConnectionError – If Redis connection cannot be established

dashboard.data_fetcher.get_remediation_stats()

Aggregate remediation statistics from Redis with 5-second cache.

Fetches events from hemostat:events:remediation_complete and calculates: - Total remediations - Success count - Failure count - Rejection count (cooldown/circuit breaker) - Success rate percentage

Returns:

Dictionary with aggregated remediation statistics

Return type:

dict[str, Any]