# Terminal UI (bunqueue top): Live Dashboard & DLQ Triage

Zero-dependency live terminal UI for bunqueue: Braille throughput charts, latency percentiles, 8 interactive views including Workflows & multi-node [8] Nodes, DLQ clustering, live controls, and k9s command palette.

Canonical: https://bunqueue.dev/guide/top/

---

`bunqueue top` is a zero-dependency live terminal dashboard built into the CLI. Watch Braille throughput waves, inspect jobs, logs, workflows, and multi-node clusters, cluster dead letters by root cause, and control queues over TCP+TLS.

**In 30 seconds**

- Zero setup: built into the bunqueue CLI; works locally, over SSH, or via kubectl port-forward.
- Streams live throughput, queues, workers, workflows, DLQ clusters, and multi-node clusters (--nodes, BUNQUEUE_NODES, or single-VIP PG discovery) over TCP+TLS with zero broker plugins.
- Switch 8 views with keys 1-8 (including [8] Nodes), pause or retry dead letters live, or press : for the command palette.

## Try it live

This interactive terminal runs the exact TypeScript engine behind `bunqueue top --demo`. Use the presets or click inside to drive it with real hotkeys (`1`–`8`, `j`/`k`, `Enter`, `Esc`, `[`/`]`, `a`, `p`, `d`, `R`, `s`, `t`, `:`, `Space`, `?`).

*[Interactive top tui simulator: open the HTML page to view it.]*

## How it works

*[Interactive ops iso diagram: One persistent TCP+TLS socket streams metrics, DLQ clusters, and live controls - Zero plugins or sidecars: bunqueue top reuses standard broker commands over port 6789 so you can triage production queues straight from your terminal - open the HTML page to view it.]*

## Quick start

```bash
bunx bunqueue top --demo                                    # 3-node cluster simulator (no server)
bunx bunqueue top                                           # local broker on localhost:6789
bunx bunqueue top --view dlq --queue billing-webhooks       # jump straight to DLQ triage

# Remote broker with auth, native TLS, 500ms refresh, and Tokyo theme
bunx bunqueue top -H queues.internal -p 6789 -t "$BQ_TOKEN" --tls -i 500 --theme tokyo
```

> **Note: Zero broker overhead**
>
> Opens one persistent, serialized MessagePack TCP socket per target and reuses standard broker commands (`DashboardOverview`, `DashboardQueues`, `DashboardQueue`, `GetQueueLimits`, `GetJob`, `GetLogs`, `GetDlqStats`, `Dlq`, `ListWebhooks`, and queue control commands)—no plugins, extra ports, or server config.

## CLI options

Honors all global connection flags (`-H/--host`, `-p/--port`, `-t/--token`, `--tls`, `--tls-ca`, `--tls-no-verify`, `--json`) plus:

| Flag | Short | Default | Description |
| --- | --- | --- | --- |
| `--interval <ms>` | `-i` | `1000` | Refresh interval in ms (`200`–`60000`). Adjustable live with `+` / `-`. |
| `--view <name>` | | `queues` | Initial view: `queues`, `workers`, `crons`, `dlq`, `webhooks`, `activity`, `workflows`, or `nodes`. |
| `--queue <name>` | `-q` | highest DLQ | Pre-select a queue (also the initial target for `--view dlq`). |
| `--theme <name>` | | `cyber` | Color theme: `cyber`, `tokyo`, `amber`, or `mono`. Cycle live with `t`. |
| `--limit <n>` | | `200` | Max recent DLQ entries analyzed per triage query (`1`–`1000`). |
| `--nodes <list>` | | env fallback | Comma-separated cluster endpoints (`[label@]host[:port],...`, repeatable; env: `BUNQUEUE_NODES`, `BQ_NODES`). |
| `--node <endpoint>` | | | Add one cluster node endpoint (repeatable shorthand for `--nodes`). |
| `--workflow-db <path>` | | env fallback | Zero-DDL SQLite Workflow Engine `dataPath` for `[7] Workflows` (env: `BUNQUEUE_WORKFLOW_DB`). |
| `--workflow-pg <url>` | | env fallback | Zero-DDL PostgreSQL 17-19 URL for `[7] Workflows` (env: `BUNQUEUE_WORKFLOW_POSTGRES_URL`; mutually exclusive with `--workflow-db`). |
| `--workflow-ns <ns>` | | `default` | PostgreSQL workflow namespace for `--workflow-pg` (env: `BUNQUEUE_WORKFLOW_POSTGRES_NAMESPACE`). |
| `--workflow-queue <q>` | | `__wf:steps` | Step queue name used when delivering workflow signals (`s`). |
| `--demo` | | `false` | Run the built-in 3-node cluster simulator without a broker. |
| `--once` | | `false` | Render one frame and exit (automatic when stdout is not a TTY). |
| `--json` | | `false` | Emit one ANSI-free JSON snapshot (with `dlqTriage` / `workflows` when selected) and exit. |

## Multi-node & Kubernetes clusters

`bunqueue top` monitors clusters in two complementary modes:

1. **Zero-config PostgreSQL discovery (single VIP / Kubernetes Service):** point at your normal Service or LoadBalancer (`bunx bunqueue top -H bunqueue.prod.svc -p 6789 -t "$BQ_TOKEN"`). PostgreSQL brokers include live `bunqueue_brokers` membership, active leases, worker counts, uptime, and stale-heartbeat detection in `DashboardOverview`, lighting up the `CLUSTER online/total` header badge and **`[8] Nodes`** with no extra flags.
2. **Direct parallel polling (`--nodes` / `--node` / `BUNQUEUE_NODES`):** poll each broker pod or VM directly for summed cluster throughput, worst-case `p95`/`p99` latency, combined heap/RSS, per-node RTT, node pinning, and automatic control failover:

```bash
# Direct multi-node polling with optional labels
bunx bunqueue top \
  --nodes "az1@10.30.0.71:6789,az2@10.30.0.72:6789,az3@10.30.0.73:6789" \
  --token "$BQ_TOKEN" --view nodes

# Or configure once via env var
export BUNQUEUE_NODES="pod-0.bunqueue-headless:6789,pod-1.bunqueue-headless:6789,pod-2.bunqueue-headless:6789"
bunx bunqueue top --token "$BQ_TOKEN"
```

- **Shared PostgreSQL clusters:** detects shared namespaces automatically—deduplicating global queue/worker/cron counts while summing per-broker throughput and memory and listing additional autoscaled PG peers as `PEER` rows.
- **Independent brokers:** aggregates queue counts, totals, throughput, and memory across online SQLite/memory nodes and routes queue/job/webhook commands to the owning node.
- **Focus & failover:** press `Enter` on a direct node in **`[8] Nodes`** (or `[` / `]`, or `:node <label|index|all>`) to scope metrics and actions to one broker; press `a` or `Esc` for `ALL NODES`. Offline brokers are marked `OFFLINE`, logged in Activity, and control commands fail over to surviving peers.

## Views and drill-down

Switch views with `1`–`8`, `Tab` / `Shift+Tab`, or `:`:

1. **Queues (`1`):** `RUNNING`/`PAUSED`, `WAIT`, tick delta (`Δ`), `PRIO`, `ACTIVE`, `DELAY`, `DLQ`, and heat-gradient `LOAD` bar. Sort with `s` (`dlq`, `waiting`, `active`, `delayed`, `name`), invert with `S`, toggle live mix bar with `v`.
2. **Workers (`2`):** active vs stale (30s heartbeat threshold), subscribed queues, active jobs, processed/failed totals, success rate, and last-seen age.
3. **Crons (`3`):** cron expression or interval, target queue, next-run countdown, run count, and safe delete (`X`).
4. **DLQ Triage (`4` or `d`):** fetches the queue's DLQ tail, scrubs dynamic noise, and groups entries into ranked root-cause clusters with attempt chains and sample job IDs.
5. **Webhooks (`5`):** ID, enabled state (`e` toggles), queue scope, credential-scrubbed URL, delivery counters, and delete (`X`).
6. **Activity (`6`):** real-time diff log of operational events between polls (DLQ spikes, pauses/resumes, worker joins/drops, disk-full alerts, operator actions).
7. **Workflows (`7` or `:wf`):** zero-DDL Workflow Engine inspector for SQLite (`--workflow-db`) or PostgreSQL 17-19 (`--workflow-pg`). `Enter` shows the step timeline, signals, and scrubbed input; `s` sends a transactional `waitFor` signal (`event` or `event={json}`).
8. **Nodes (`8` or `:nodes`):** cluster roster of direct nodes and PG peers with status (`ONLINE`, `PEER`, `DEGRADED`, `STALE`, `OFFLINE`), `PUSH/S`, `P99`, `HEAP/RSS`, active leases, uptime, and RTT / heartbeat age. `Enter` focuses a direct node; `a` returns to `ALL NODES`.

**Drill-down:** `Enter` on a queue opens **Queue Inspect** (rate/concurrency limits, stacked state bar, job previews across active/waiting/paused/delayed/DLQ). `Enter` on any job opens **Job Inspect** (metadata, redacted JSON payload, latest logs, plus `m` promote, `x` cancel, `X` discard). `Esc` or `Backspace` steps back.

## DLQ clustering and secret scrubbing

Before rendering or clustering, a deterministic scrubber runs on all broker-supplied strings:

- **Terminal safety:** strips CSI, OSC (`\x1b]...BEL`/`ST`), DCS/APC/PM/SOS escape sequences, and control characters from labels, errors, prompts, and payloads.
- **Secret redaction:** masks Bearer tokens, JWTs, `password`/`secret`/`token`/`api_key`/`authorization`/`cookie` pairs, provider keys (`sk_live_*`, `pk_live_*`), email addresses, webhook URL credentials (`user:pass@`), and sensitive query params (`?token=`, `?api_key=`).
- **Root-cause normalization:** replaces UUIDs, ISO timestamps, IPv4 addresses, `req_*`/`evt_*`/`job_*` IDs, hex strings, and numbers with placeholders so noisy retries collapse into actionable clusters.
- **Canary retry:** press **`R`** to retry one sample job first, then **`A`** to retry all or **`P`** to purge.

## Keybindings and command palette

All destructive or bulk mutations (`D`, `R`, `A`, `P`, `x`, `X`, `M`) require explicit **`y/N`** confirmation before sending any command.

| Keys | Action |
| --- | --- |
| `1`..`8` / `Tab` / `Shift+Tab` | Switch between the 8 views |
| `↑` `↓` / `j` `k` / `PgUp` `PgDn` / `g` `G` | Navigate lists and jump top/bottom |
| `Enter` / `Esc` | Drill down (Queue -> Job + Logs, Workflow -> Steps), focus node in Nodes / step back |
| `[` / `]` or `a` (in Nodes) | Cycle focused cluster node / return to `ALL NODES` aggregate |
| `/` | Live filter on current view (`Enter` locks, `Esc` clears) |
| `:` | Open `k9s`-style command palette (`:nodes`, `:node <id\|all>`, `:wf`, `:dlq`, `:theme`, `:pause`, `:compact`) |
| `s` / `S` | Cycle queue sort column / reverse sort (or send signal in `[7] Workflows`) |
| `p` | Pause or resume selected queue |
| `d` | Jump to DLQ Triage for selected queue |
| `l` / `c` | Set or clear (`0`) rate limit (jobs/s) or concurrency limit |
| `n` | Quick-push a JSON job (`Enter` on empty pushes `{}`) |
| `D` | Drain all waiting jobs in selected queue (`y/N`) |
| `R` / `A` / `P` | In DLQ: canary retry 1 sample / retry all / purge (`y/N`) |
| `x` / `m` / `X` | In Job Inspect: cancel (`y/N`) / promote delayed / discard (`y/N`) |
| `e` / `X` | In Webhooks/Crons: toggle enabled / remove (`y/N`) |
| `M` | Compact broker memory (`y/N`) |
| `t` / `v` / `+` `-` / `Space` / `r` | Cycle theme / toggle split bar / speed / freeze / refresh now |
| `?` / `q` / `Ctrl+C` | Toggle help overlay / quit and restore terminal |

### Command palette (`:`)

- **Views:** `:queues` (`:queue`), `:workers` (`:w`), `:crons` (`:c`), `:dlq [queue]` (`:triage [queue]`), `:webhooks` (`:wh`), `:activity` (`:act`, `:events`, `:log`), `:workflows` (`:wf`), `:nodes` (`:n`, `:cluster`, `:brokers`)
- **Cluster focus:** `:node <label|brokerId|index|all>` (`:focus <target>`)
- **Operations:** `:pause <queue>`, `:resume <queue>`, `:drain <queue>` (`y/N`), `:compact` (`:gc`, `y/N` — compacts all online nodes in `ALL NODES` mode)
- **Session:** `:theme <cyber|tokyo|amber|mono>`, `:help`, `:q` / `:quit` / `:exit`

## Scripting, CI, and color policy

```bash
bunx bunqueue top --once -H 127.0.0.1 -p 6789                              # plain snapshot (ANSI auto-off on pipes)
FORCE_COLOR=1 bunx bunqueue top --once --theme cyber                      # force ANSI into a file or pager
bunx bunqueue top --json --view dlq -q billing-webhooks | jq '.dlqTriage.clusters'
```

- **Exit codes:** `0` clean exit (`q`, signal, `--help`, `--once`, `--json`); `1` connection, auth, or broker error; `2` invalid CLI flag/value (validated before connecting).
- **Color & viewport:** respects `FORCE_COLOR`, `NO_COLOR`, and `TERM=dumb`; `--json` is strictly ANSI-free. Terminals smaller than `60x14` render a fitted resize notice without wrapping.

## Next steps

- Launch deep dive: [Introducing `bunqueue top`](https://bunqueue.dev/blog/bunqueue-top/).
- Full CLI & transport security: [CLI Reference](https://bunqueue.dev/guide/cli/) and [TLS Encryption](https://bunqueue.dev/guide/tls/).
