duck.cli.commands.monitor

Real-time Duck system monitor with per-process metrics and a visuals history table.

New features:

  • Rolling history buffer for key metrics (cpu_total, ram_percent, disk_percent, net_up, net_down)

  • Visuals table below process tables with sparklines, min/max/avg/current

  • History length is configurable (default 8 samples)

Module Contents

Classes

MonitorCommand

Real-time Duck system monitor with per-process metrics and a visuals history table.

Data

console

API

class duck.cli.commands.monitor.MonitorCommand[source]

Real-time Duck system monitor with per-process metrics and a visuals history table.

New features:

  • Rolling history buffer for key metrics (cpu_total, ram_percent, disk_percent, net_up, net_down)

  • Visuals table below process tables with sparklines, min/max/avg/current

  • History length is configurable (default 30 samples)

SPARK_SYMBOLS

‘▁▂▃▄▅▆▇█’

classmethod disk()[source]

Return root disk usage in GB as a dictionary: {‘root’: str, ‘used’: float, ‘total’: float, ‘free’: float, ‘percent’: float}

classmethod get_duck_processes(name: str, pids: Optional[List[int]] = None, sort_by: str = 'cpu')[source]

Return filtered Duck processes sorted by CPU or RAM.

Features:

  • Wildcard support: use ‘*’ or ‘?’ in the name parameter.

  • Filter by PID list if provided.

  • Sort by ‘cpu’ or ‘ram’.

Example:

  • name=‘duck*’ matches ‘duck’, ‘duck_server’, etc.

  • name=‘server’ matches any process containing ‘server’.

classmethod get_system_metrics(prev_disk, prev_net, elapsed)[source]

Return CPU, RAM, Disk, Network metrics with failsafe handling.

classmethod main(interval: float = 1.0, duck_process_name: str = 'duck*', duck_pids: Optional[List[int]] = None, sort_by: str = 'cpu', cpu_warning: float = 80.0, ram_warning: float = 80.0, history_length: int = 8)[source]

Start a live monitoring loop for system metrics and Duck processes, with visualized history of CPU and RAM usage.

This method continuously updates a live console display showing system-wide metrics (CPU, RAM, Disk, Network) alongside per-process metrics for Duck processes filtered by name or PID. A rolling history table provides a visual representation of recent usage trends.

Parameters:
  • interval – Refresh interval in seconds. Defaults to 1.0.

  • duck_process_name – Process name pattern to monitor (supports wildcards). Defaults to “duck*”.

  • duck_pids – Specific process IDs to monitor. If None, all matching processes are included. Defaults to None.

  • sort_by – Metric to sort Duck processes by; either ‘cpu’ or ‘ram’. Defaults to “cpu”.

  • cpu_warning – CPU usage threshold (%) to highlight warnings. Defaults to 80.0.

  • ram_warning – RAM usage threshold (%) to highlight warnings. Defaults to 80.0.

  • history_length – Number of recent samples to retain for the visuals/history table. Defaults to 8.

Returns:

This method runs indefinitely until interrupted by the user.

Return type:

None

classmethod make_duck_process_tables(processes)[source]

Return two tables for Duck processes:

  1. PID, Name, CPU%, RAM%, Threads

  2. Disk Read, Disk Write, Network Sent, Network Received

classmethod make_history_table(history: List[Dict[str, Any]], cpu_warning: float, ram_warning: float, width: int = 30)[source]

Build a visuals/history table showing sparklines and summary stats. history: list of dict entries with keys ‘cpu’, ‘ram’, ‘disk’, ‘net_up’, ‘net_down’

classmethod make_system_table(cpu_per_core, ram_str, disk_str, net_str)[source]

Return the main system metrics table.

classmethod render_trend_bar(value: float, max_value: float = 100) rich.text.Text[source]

Return a slim unicode trend block with color based on value.

classmethod sparkline_from_values(values: List[float], max_value: float = 100, width: Optional[int] = None) str[source]

Create a compact sparkline string from a list of values.

duck.cli.commands.monitor.console

‘Console(…)’